Can I convert a geometry point to wkt including the srid formatted. See below the example.
"SRID=4326;POINT(-43.9725637435913 -19.9411078674228)".
Although I tried to put point.toText() only return the coordinate without the srid.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityCan I convert a geometry point to wkt including the srid formatted. See below the example.
"SRID=4326;POINT(-43.9725637435913 -19.9411078674228)".
Although I tried to put point.toText() only return the coordinate without the srid.
You can't (currently) read EWKT directly - the simplest route is to split the string at ;
and handle the two parts.
public static void main(String[] args) throws IOException, NoSuchAuthorityCodeException, FactoryException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
WKTReader2 reader = new WKTReader2();
String line = "";
while((line=in.readLine())!=null) {
try {
Geometry g;
if(line.contains(";")) {
String[] parts = line.split(";");
CRS.decode("EPSG:"+parts[0].substring(5));
g = reader.read(parts[1]);
} else {
g = reader.read(line);
}
System.out.println("\t"+g);
} catch (ParseException e) {
System.out.println("invalid input");
e.printStackTrace();
}
}
}
}
If you want to write EWKT out then you need to look up (and probably cache) the EPSG code from your projection object.
Point p = GenerateRandomData.createRandomPoint();
CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
StringBuffer buffer = new StringBuffer();
buffer.append("SRID=");
buffer.append(CRS.lookupEpsgCode(crs, false)).append(';');
WKTWriter2 writer = new WKTWriter2();
buffer.append(writer.write(p));
System.out.println(buffer.toString());