| | |
| | | Filter filter = Filter.INCLUDE; |
| | | FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter); |
| | | return collection; |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param zipFile: |
| | | * @return JSONObject |
| | |
| | | */ |
| | | public static List<String> shpToGeoJson(File zipFile) throws IOException { |
| | | FeatureJSON fjson = new FeatureJSON(); |
| | | JSONObject geoJsonObject=new JSONObject(); |
| | | geoJsonObject.put("type","FeatureCollection"); |
| | | List<String> strings=new ArrayList<>(); |
| | | JSONObject geoJsonObject = new JSONObject(); |
| | | geoJsonObject.put("type", "FeatureCollection"); |
| | | List<String> strings = new ArrayList<>(); |
| | | try { |
| | | // 获取FeatureCollection |
| | | FeatureCollection collection = getFeatureCollectionByShpFile(zipFile); |
| | | |
| | | FeatureIterator iterator = collection.features(); |
| | | List<JSONObject> array = new ArrayList<JSONObject>(); |
| | | List<JSONObject> array = new ArrayList<JSONObject>(); |
| | | //遍历feature转为json对象 |
| | | while (iterator.hasNext()) { |
| | | SimpleFeature feature = (SimpleFeature) iterator.next(); |
| | |
| | | } |
| | | iterator.close(); |
| | | //添加到geojsonObject |
| | | geoJsonObject.put("features",array); |
| | | geoJsonObject.put("features", array); |
| | | iterator.close(); |
| | | |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | throw e; |
| | | } |
| | | return strings; |