Java 将ED_1950_UTM_分区_32N(23032)转换为WGS84

Java 将ED_1950_UTM_分区_32N(23032)转换为WGS84,java,geospatial,coordinate-systems,geotools,wgs84,Java,Geospatial,Coordinate Systems,Geotools,Wgs84,我需要使用上述坐标系将Shapefile导入并处理到使用WGS84坐标系的Java应用程序中 更具体地说,我读取shapefile并提取多边形,然后将每个多边形存储到数据库中的一个对象中。稍后,我将不得不将空间点与这些多边形进行比较(检查点是否在其多边形中)。点和多边形位于不同的CRS中这一事实似乎是我达到0命中率的原因 虽然我认为这无关紧要,但以下是我如何使用GeoTools阅读shapefile: InputStream stream = new FileInputStrea

我需要使用上述坐标系将Shapefile导入并处理到使用WGS84坐标系的Java应用程序中

更具体地说,我读取shapefile并提取多边形,然后将每个多边形存储到数据库中的一个对象中。稍后,我将不得不将空间点与这些多边形进行比较(检查点是否在其多边形中)。点和多边形位于不同的CRS中这一事实似乎是我达到0命中率的原因

虽然我认为这无关紧要,但以下是我如何使用GeoTools阅读shapefile:

        InputStream stream = new FileInputStream("path/to/file");

        File tempDir = File.createTempFile("shapefile_temp", "");

        if (tempDir.exists())
            tempDir.delete();
        tempDir.mkdir();

        URL shpName = null;

        Files.unzip(stream, tempDir);

        for (File file : tempDir.listFiles())
            if (file.getName()
                    .endsWith(".shp"))
            {
                shpName = file.toURI()
                              .toURL();
                break;
            }

        if (shpName == null)
            throw new RuntimeException("No SHP found");

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("url", shpName);
        DataStore dataStore = DataStoreFinder.getDataStore(map);

        try
        {
            String typeName = dataStore.getTypeNames()[0];

            FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(typeName);

            FeatureIterator<SimpleFeature> iterator = source.getFeatures()
                                                            .features();

            while (iterator.hasNext())
            {

                Feature feature = iterator.next();

                System.out.println();
                System.out.println((int) feature.getProperty("COD_PRO")
                                                .getValue() + "\t" + feature.getProperty("NOME_PRO")
                                                                            .getValue());
                System.out.println(feature.getDefaultGeometryProperty()
                                          .getValue()); //This thing will be stored in a CQEngine and compared against a given point
            }

        }
        finally
        {
            tempDir.delete();
        }

    }
    finally
    {
        System.gc();
    }

如何从ED_1950转换多边形。。。到WGS84?或者,如何将WGS84点与ED_1950多边形进行比较?

首先需要从丹麦到WGS84的变换:

CoordinateReferenceSystem worldCRS = CRS.decode("EPSG:4326");
CoordinateReferenceSystem ed_1950 = CRS.decode("EPSG:23032");
boolean lenient = true; // allow for some error due to different datums
MathTransform transform = CRS.findMathTransform(ed_1950, worldCRS, lenient);
然后,对于添加到数据库中的每个几何体,需要对其进行变换:

Geometry geometry = (Geometry) feature.getDefaultGeometry();
Geometry geometry2 = JTS.transform(geometry, transform);
(我实际上还没有编译这段代码,但它应该可以工作-请参阅此了解更多详细信息)。

错误:没有为“EngineeringCRS”类型的对象找到来自权威机构“EPSG”的代码“EPSG:4326”。我试图自己找到解决方案,但如果你有想法,请分享,确保你的pom中有org.geotools gt epsg hsql${geotools.version}
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Geometry geometry2 = JTS.transform(geometry, transform);