Решение Geotools для чтения шейп-файла в EPSG3035, чтобы получить долгую / широту в WGS84?

Координаты шейп-файла находятся в EPSG3035, и мне нужно читать их в обычных длинных координатах.

Как я могу сделать это с помощью Geotools?

Мой код без преобразования на данный момент:

ShapefileDataStore dataStore = new ShapefileDataStore(file.toURL());
ContentFeatureSource featureSource = dataStore.getFeatureSource();
ContentFeatureCollection featureCollection = featureSource.getFeatures();
SimpleFeatureIterator iterator = featureCollection.features();

while (iterator.hasNext()) {
   SimpleFeature feature = iterator.next();
   Collection<Property> properties = feature.getProperties();
   etc...
}

Спасибо!


person seinecle    schedule 04.06.2015    source источник


Ответы (1)


Не проверял, но так и должно работать. Смотрите мои комментарии в строке:

ShapefileDataStore dataStore = new ShapefileDataStore(file.toURL());
ContentFeatureSource featureSource = dataStore.getFeatureSource();
ContentFeatureCollection featureCollection = featureSource.getFeatures();
SimpleFeatureIterator iterator = featureCollection.features();

// get dynamically the CRS of your data:
SimpleFeatureType schema = featureSource.getSchema();
CoordinateReferenceSystem sourceCRS = schema.getCoordinateReferenceSystem();

// OR fallback to hardcoded 3035 if the above fails:
// CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3035")

CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326") // the coordinates system you want to reproject the data to
// define a MathTransform object
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);


while (iterator.hasNext()) {
   SimpleFeature feature = iterator.next();
   Collection<Property> properties = feature.getProperties();

   // get the geometry of the actual feature
   Geometry sourceGeometry = feature.getDefaultGeometry()
   // transform the geometry and save it in a new variable
   Geometry reprojectedGeometry = JTS.transform(sourceGeometry, transform)
   // set the reprojected geometry as the geometry of the actual feature
   feature.setDefaultGeometry(reprojectedGeometry)
   // .....
}

Для получения дополнительной информации см. Это руководство: Руководство по геометрии CRS

person Tom-db    schedule 05.06.2015
comment
Лучшей практикой было бы запросить у хранилища данных его crs, а не форсировать 3035. Затем вернуться к форсированию, если файл .prj отсутствует - person Ian Turton; 10.06.2015