【问题标题】:Converting from UTM to WGS84 using GeoTools with missing .prj file?使用缺少 .prj 文件的 GeoTools 从 UTM 转换为 WGS84?
【发布时间】:2019-11-03 10:29:16
【问题描述】:

我有一个读取一组坐标的函数,我得到了 UTM 坐标。后来我将这些 UTM 坐标转换为 WGS84。当此数据来自 4 个文件(shp、.dbf、.shx 和 .prj)的集合时,没有问题。

这是我获取坐标并转换它们的代码:

public Geometry getGeometryDistrict(String refCatDistrict, String shapeFileDistrict){

                Geometry union = null;

                File shapeFile = new File (shapeFileDistrict);

                try {

                   Query query = new Query();
                   query.setCoordinateSystem(DefaultGeographicCRS.WGS84);

                   Filter filter = CQL.toFilter("obj_co_id = '"+refCatDistrict+"'");
                   query.setFilter(filter);

                   FileDataStore storeDistrict = FileDataStoreFinder.getDataStore(shapeFile);

                   SimpleFeatureSource featureSource = storeDistrict.getFeatureSource();

                   SimpleFeatureCollection collection = featureSource.getFeatures(query);
                   SimpleFeature fDistrict = null;

                   ArrayList<Geometry> geometries = new ArrayList<>();

                   SimpleFeatureIterator itrDistrict = collection.features();

                   while(itrDistrict.hasNext()){

                      fDistrict = itrDistrict.next();

                      Geometry geomDistrict = (Geometry)fDistrict.getDefaultGeometry();
                      geometries.add(geomDistrict);

                   }

                   GeometryFactory factory = new GeometryFactory();

                   GeometryCollection geometryCollection = (GeometryCollection) factory.buildGeometry( geometries );

                   union = geometryCollection.union();

                   itrDistrict.close();
                   storeDistrict.dispose();

               }catch(IOException | NoSuchElementException | CQLException e){
                   Throwable cause = e.getCause();
                   System.out.println(cause);
               }

                return union;
            }

我的问题是这些数据并不总是有 .prj 文件(需要转换坐标),只有 3 个文件到达(.dbf、.shp 和 .shx)。

我的疑问是:是否有任何方法可以在没有 .prj 文件的情况下将 UTM 坐标转换为 WGS84?

【问题讨论】:

  • 没有.prj 文件,你只有一个随机数的集合
  • OP 知道坐标在 UTM 中并希望转换为 WGS84。如果他想将 UTM 中的 shapefile 转换为 WGS84,即使没有 .prj 文件或任意坐标对,我也不清楚。

标签: java gis utm wgs84


【解决方案1】:

如果没有 prj,您无法将 UTM 坐标转换为 WGS84。您需要 Central Meridian 或 UTM Zone 进行转换。

但是有一个解决方法。您可以使用 World UTM zone 预测 UTM 区域。如果您知道确切的区域,则可以这样做。然后通过反复试验,您可以转换并检查附近的 2-3 个区域。

【解决方案2】:

我找到了这个解决方案,显然它工作正常:

 try{      

   CoordinateReferenceSystem sourceutm = CRS.decode(String.format("AUTO2:42001,%s,%s", -3.691406, 40.403431), true);
   CoordinateReferenceSystem targetlatlong = CRS.decode("EPSG:4326", true);

   MathTransform transform = CRS.findMathTransform(sourceutm, targetlatlong, false);
   Geometry union = JTS.transform( geometryCollection, transform);

   System.out.println(union.toString());

  }catch(MismatchedDimensionException | FactoryException | TransformException e){
         throw new RuntimeException(e);
       }    

当然,这在里面。并从 UTM 返回我的度坐标。不需要 .pjr。

【讨论】:

  • 您正在通过 CRS。那本身就是prj的内容!如果您知道文件的 CRS,那么显然您不需要 prj
猜你喜欢
  • 2013-08-16
  • 2014-07-20
  • 2021-06-04
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2018-12-22
  • 2020-05-29
  • 1970-01-01
相关资源
最近更新 更多