|
@@ -2,6 +2,9 @@ package com.zjugis.ysgzybz.utils;
|
|
|
|
|
|
import com.vividsolutions.jts.geom.Geometry;
|
|
|
import com.vividsolutions.jts.geom.GeometryCollection;
|
|
|
+import com.vividsolutions.jts.geom.GeometryFactory;
|
|
|
+import com.vividsolutions.jts.io.ParseException;
|
|
|
+import com.vividsolutions.jts.io.WKTReader;
|
|
|
import com.vividsolutions.jts.operation.buffer.BufferOp;
|
|
|
import com.vividsolutions.jts.operation.buffer.BufferParameters;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -50,6 +53,11 @@ public class GisUtils {
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
+ public static Geometry parseWkt(String wktStr) throws ParseException {
|
|
|
+ GeometryFactory geometryFactory = new GeometryFactory();
|
|
|
+ WKTReader reader = new WKTReader(geometryFactory);
|
|
|
+ return (Geometry) reader.read(wktStr);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 判断点是否位于polygon的缓冲区内
|
|
@@ -59,16 +67,17 @@ public class GisUtils {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static boolean isPointLocate(String point, String polygon) throws IOException {
|
|
|
+ public static boolean isPointLocate(String point, String polygon) throws ParseException, IOException {
|
|
|
if (StringUtils.isEmpty(point)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (StringUtils.isEmpty(polygon)) {
|
|
|
return false;
|
|
|
}
|
|
|
- Geometry geometry = parseGeojson(polygon);
|
|
|
+ Geometry geometry = parseWkt(polygon);
|
|
|
Geometry transformGeoemtry = crsTransform(geometry, 4490, 4326);
|
|
|
- double degree = 500 / (2 * Math.PI * 6371004) * 360;//将meter转换为度
|
|
|
+ double bufferDistance = 500d;//缓冲距离
|
|
|
+ double degree = bufferDistance / (2 * Math.PI * 6371004) * 360;//将meter转换为度
|
|
|
Geometry buffer = transformGeoemtry.buffer(degree);
|
|
|
System.out.println("buffer500:" + buffer.toText());
|
|
|
Geometry pointGeo = parseGeojson(point);
|
|
@@ -112,11 +121,11 @@ public class GisUtils {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
-// String geojson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"id\":\"bjwkfly2000.65\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[120.17376215,30.1550689],[120.17371998,30.15505164],[120.17351625,30.1552117],[120.17387465,30.15554496],[120.17380729,30.15560406],[120.17392119,30.15571815],[120.17400582,30.15586233],[120.17405761,30.15579803],[120.17412072,30.1557161],[120.17416208,30.15566551],[120.17416494,30.15561077],[120.17415718,30.15557068],[120.17407017,30.15544573],[120.17392918,30.15523398],[120.17376215,30.1550689]]]]},\"geometry_name\":\"shape\",\"properties\":{\"id\":65,\"objectid\":71,\"OBJECTID_1\":65,\"dkbh\":\"CH-86\",\"dkmj\":\"2230.52957561753\",\"dkwz\":\"长河街道\",\"mj\":3.35,\"dkxz\":\"土方;空地\",\"gddw\":\"城建发展公司\",\"lxr\":\"蒋鹏飞\",\"lxdh\":\"13867121627\",\"bz\":\" \",\"szfw\":\"东至长桥线,南至空地,西至仓库,北至长桥线\",\"st_area_sh\":2.1E-7,\"st_length_\":0.00220052,\"shape_leng\":0.00220052,\"dksyh\":\"480a668a9e4c11ee94c4074096d72126\",\"st_area_shape_\":2.1E-7,\"st_length_shape_\":0.00220052,\"st_area_shape1\":2.1E-7,\"st_length_shape1\":0.00220052,\"st_area_shape1_1\":2.1E-7,\"st_length_shape1_1\":0.00220052,\"st_area_shape1_12\":2.1E-7,\"st_length_shape1_12\":0.00220052,\"shape_Length\":0.0022005175620851926,\"shape_Area\":2.088635342349575E-7}}],\"totalFeatures\":1,\"numberMatched\":1,\"numberReturned\":1,\"timeStamp\":\"2024-06-18T08:00:11.960Z\"}";
|
|
|
- String geojson = "{\"type\":\"MultiPolygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4490\"}},\"coordinates\":[[[[120.185892363,30.150623136],[120.185830634,30.150590162],[120.185758439,30.150699298],[120.185532579,30.150868505],[120.185306728,30.151037711],[120.1855314,30.1512482],[120.185756096,30.15145869],[120.185883776,30.151650994],[120.186193588,30.151911057],[120.186503391,30.152171119],[120.186645222,30.152280673],[120.186819674,30.152415447],[120.187039065,30.152178015],[120.187121981,30.152062935],[120.187205372,30.151947179],[120.187241939,30.151896439],[120.187371691,30.151716362],[120.187537998,30.151485526],[120.187456279,30.151442713],[120.187195629,30.151306113],[120.186934971,30.151169522],[120.186760665,30.151078174],[120.186674322,30.151032931],[120.186413665,30.15089633],[120.186153019,30.150759738],[120.185892363,30.150623136]]]]}";
|
|
|
- String point = "{\"type\":\"Point\",\"coordinates\":[120.17396,30.15565]}";
|
|
|
- boolean pointLocate = GisUtils.isPointLocate(point, geojson);
|
|
|
- System.out.println(pointLocate);
|
|
|
- }
|
|
|
+// public static void main(String[] args) throws IOException {
|
|
|
+//// String geojson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"id\":\"bjwkfly2000.65\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[120.17376215,30.1550689],[120.17371998,30.15505164],[120.17351625,30.1552117],[120.17387465,30.15554496],[120.17380729,30.15560406],[120.17392119,30.15571815],[120.17400582,30.15586233],[120.17405761,30.15579803],[120.17412072,30.1557161],[120.17416208,30.15566551],[120.17416494,30.15561077],[120.17415718,30.15557068],[120.17407017,30.15544573],[120.17392918,30.15523398],[120.17376215,30.1550689]]]]},\"geometry_name\":\"shape\",\"properties\":{\"id\":65,\"objectid\":71,\"OBJECTID_1\":65,\"dkbh\":\"CH-86\",\"dkmj\":\"2230.52957561753\",\"dkwz\":\"长河街道\",\"mj\":3.35,\"dkxz\":\"土方;空地\",\"gddw\":\"城建发展公司\",\"lxr\":\"蒋鹏飞\",\"lxdh\":\"13867121627\",\"bz\":\" \",\"szfw\":\"东至长桥线,南至空地,西至仓库,北至长桥线\",\"st_area_sh\":2.1E-7,\"st_length_\":0.00220052,\"shape_leng\":0.00220052,\"dksyh\":\"480a668a9e4c11ee94c4074096d72126\",\"st_area_shape_\":2.1E-7,\"st_length_shape_\":0.00220052,\"st_area_shape1\":2.1E-7,\"st_length_shape1\":0.00220052,\"st_area_shape1_1\":2.1E-7,\"st_length_shape1_1\":0.00220052,\"st_area_shape1_12\":2.1E-7,\"st_length_shape1_12\":0.00220052,\"shape_Length\":0.0022005175620851926,\"shape_Area\":2.088635342349575E-7}}],\"totalFeatures\":1,\"numberMatched\":1,\"numberReturned\":1,\"timeStamp\":\"2024-06-18T08:00:11.960Z\"}";
|
|
|
+// String geojson = "{\"type\":\"MultiPolygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4490\"}},\"coordinates\":[[[[120.185892363,30.150623136],[120.185830634,30.150590162],[120.185758439,30.150699298],[120.185532579,30.150868505],[120.185306728,30.151037711],[120.1855314,30.1512482],[120.185756096,30.15145869],[120.185883776,30.151650994],[120.186193588,30.151911057],[120.186503391,30.152171119],[120.186645222,30.152280673],[120.186819674,30.152415447],[120.187039065,30.152178015],[120.187121981,30.152062935],[120.187205372,30.151947179],[120.187241939,30.151896439],[120.187371691,30.151716362],[120.187537998,30.151485526],[120.187456279,30.151442713],[120.187195629,30.151306113],[120.186934971,30.151169522],[120.186760665,30.151078174],[120.186674322,30.151032931],[120.186413665,30.15089633],[120.186153019,30.150759738],[120.185892363,30.150623136]]]]}";
|
|
|
+// String point = "{\"type\":\"Point\",\"coordinates\":[120.17396,30.15565]}";
|
|
|
+// boolean pointLocate = GisUtils.isPointLocate(point, geojson);
|
|
|
+// System.out.println(pointLocate);
|
|
|
+// }
|
|
|
}
|