初始化
This commit is contained in:
parent
28c98e6c09
commit
e838d2cb88
@ -2,16 +2,21 @@ package com.gis3c.spatial.common;
|
||||
|
||||
|
||||
import com.gis3c.spatial.entity.BaseFeature;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.factory.CommonFactoryFinder;
|
||||
import org.geotools.filter.text.cql2.CQL;
|
||||
import org.geotools.filter.text.cql2.CQLException;
|
||||
import org.geotools.geojson.feature.FeatureJSON;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterFactory2;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by hukekuan on 2018/1/16.
|
||||
@ -165,4 +170,34 @@ public class FeatureUtilities {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static SimpleFeatureCollection FeatureCollectionFilter(
|
||||
SimpleFeatureCollection featureCollection, Geometry geometry,String whereClause) throws CQLException {
|
||||
SimpleFeatureCollection resultCollection = null;
|
||||
if(featureCollection == null || featureCollection.size() == 0){
|
||||
return featureCollection;
|
||||
}
|
||||
if(geometry == null && (whereClause == null || "".equals(whereClause))){
|
||||
throw new IllegalArgumentException("参数输入有误");
|
||||
}
|
||||
|
||||
FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
|
||||
List<Filter> filterList = new ArrayList<>();
|
||||
if(geometry != null){
|
||||
if(geometry.getSRID() == 0){
|
||||
geometry.setSRID(4326);
|
||||
}
|
||||
String geometryPropertyName = featureCollection.getSchema().getGeometryDescriptor().getLocalName();
|
||||
filterList.add(filterFactory.intersects(filterFactory.property(geometryPropertyName), filterFactory.literal(geometry)));
|
||||
}
|
||||
if(whereClause != null && !"".equals(whereClause)){
|
||||
filterList.add(CQL.toFilter(whereClause));
|
||||
}
|
||||
if(filterList.size() == 1){
|
||||
resultCollection = featureCollection.subCollection(filterList.get(0));
|
||||
}else if(filterList.size() == 2){
|
||||
resultCollection = featureCollection.subCollection(filterFactory.and(filterList.get(0),filterList.get(1)));
|
||||
}
|
||||
return resultCollection;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class GeometryUtilities {
|
||||
* @return
|
||||
*/
|
||||
public static Point CreatePoint(double lon, double lat){
|
||||
return geomFactory.createPoint(new Coordinate(lat, lon));
|
||||
return geomFactory.createPoint(new Coordinate(lon,lat));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,7 +324,7 @@ public class GeometryUtilities {
|
||||
* @param distance
|
||||
* @return
|
||||
*/
|
||||
public Polygon CreateBuffer(Geometry geometry,Double distance){
|
||||
public static Polygon CreateBuffer(Geometry geometry,Double distance){
|
||||
Polygon bufferResult = null;
|
||||
if(geometry == null || distance == null){
|
||||
throw new IllegalArgumentException("参数输入有误");
|
||||
|
||||
@ -37,13 +37,18 @@ public class App {
|
||||
ApplicationContext context = ApplicationInit();
|
||||
|
||||
|
||||
Point start = GeometryUtilities.CreatePoint(118.024444,36.802778);
|
||||
Point end = GeometryUtilities.CreatePoint(118.027777,36.759166);
|
||||
try {
|
||||
System.out.println(GeometryUtilities.PointDistance(start,end));
|
||||
} catch (TransformException | FactoryException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<Double> data = new ArrayList<>(Arrays.asList(new Double[]{1.1,2.1,3.1}));
|
||||
Double result = data.stream().max(Comparator.naturalOrder()).get();
|
||||
System.out.println(result);
|
||||
|
||||
|
||||
// Point start = GeometryUtilities.CreatePoint(118.024444,36.802778);
|
||||
// Point end = GeometryUtilities.CreatePoint(118.027777,36.759166);
|
||||
// try {
|
||||
// System.out.println(GeometryUtilities.PointDistance(start,end));
|
||||
// } catch (TransformException | FactoryException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
// List<Region> regionList = regionService.findRegionsByParentCode("370000");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user