I have a function that reads a set of coordinates and I get UTM coordinates. Later I convert these UTM coordinates to WGS84. No problems when this data comes from the set of 4 files (shp, .dbf, .shx and .prj).
This is my code to get the coordinates and convert them:
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;
}
My problem is that these data do not always have the .prj file (needed to convert the coordinates), and only 3 files arrive (.dbf, .shp and .shx).
My Doubt is: Would there be any way to convert UTM coordinates to WGS84 without having the .prj file?