我在“EPSG:3857”中重新投影了一个形状文件,并且我试图在一定范围内查找以米我得到一个点经纬度(WGS84)。Java GeoTools使用WGS84输入和“EPSG:3857”形状搜索范围内的功能
使用dwithin我需要通过一个高于实际距离的范围,所以得到这种情况是因为“EPSG:3857”和dwithin的问题,我切换到缓冲几何图形,寻找距离我一定距离的特征点。这是我的代码:
CoordinateReferenceSystem WGS84 = CRS.decode("EPSG:4326",true); //org.geotools.referencing.crs.DefaultGeographicCRS.WGS84 Google Earth;
CoordinateReferenceSystem EPSG3857 = CRS.decode("EPSG:3857",true); //WGS84 Pseudo-Mercator: shape reprojected CRS------------- String code = "AUTO:42001," + x + "," + y;
MathTransform transformToEPSG3857 = CRS.findMathTransform(WGS84, EPSG3857, false);
GeometryFactory geometryFactory2 = new GeometryFactory();
Geometry pointSource = geometryFactory.createPoint(coordinateSource); // coordinateSource is lat=41.942667 lon=12.462218
Geometry targetGeometry = JTS.transform(pointSource, transformToEPSG3857);
Geometry buffer = targetGeometry.buffer(distance);
buffer.setSRID(3857);
Filter pointInPolygon = filterFactory.contains(filterFactory.property("the_geom"), filterFactory.literal(buffer));
SimpleFeatureCollection features = shapeFileNamedCache.getFeatureSource().getFeatures(pointInPolygon);
System.out.println("Features: " + features.size() + " at distance in meters: " + distance);
我没有得到为什么这个代码不筛选出任何功能,而我知道有。
任何意见将帮助我。
Stefano。
缓冲区包含此:
POLYGON ((1387457.7619147683 5152395.103885399, 1387454.4954124368 5152361.9385306565, 1387444.8214352953 5152330.047701897, 1387429.1117488598 5152300.6569457855, 1387407.97006757 5152274.895732597, 1387382.2088543817 5152253.754051308, 1387352.8180982703 5152238.044364872, 1387320.927269511 5152228.37038773, 1387287.7619147683 5152225.103885399, 1387254.5965600256 5152228.37038773, 1387222.7057312662 5152238.044364872, 1387193.3149751548 5152253.754051308, 1387167.5537619665 5152274.895732597, 1387146.4120806768 5152300.6569457855, 1387130.7023942412 5152330.047701897, 1387121.0284170997 5152361.9385306565, 1387117.7619147683 5152395.103885399, 1387121.0284170997 5152428.269240142, 1387130.7023942412 5152460.160068901, 1387146.4120806768 5152489.550825013, 1387167.5537619665 5152515.312038201, 1387193.3149751548 5152536.45371949, 1387222.7057312662 5152552.163405926, 1387254.5965600256 5152561.837383068, 1387287.7619147683 5152565.103885399, 1387320.927269511 5152561.837383068, 1387352.8180982703 5152552.163405926, 1387382.2088543817 5152536.45371949, 1387407.97006757 5152515.312038201, 1387429.1117488598 5152489.550825013, 1387444.8214352953 5152460.160068901, 1387454.4954124368 5152428.269240142, 1387457.7619147683 5152395.103885399))
米我通过170,但性能更接近。 Shape文件通过QGIS重新投影到WGS84伪墨卡托投影机中。奇怪的是,如果我使用CRS为ED_1950_UTM_Zone_33N的原始文件,距离是正确的,并且功能更接近预期(发现在123米而不是167)。
什么是缓冲区等于,请将WKT添加到问题中。你如何重新塑造shapefile? –
请编辑问题 –
已编辑的问题。谢谢所有:) – caramelleas