/** * Sets the SRID, if it was specified in the WKB * * @param g the geometry to update * @return the geometry with an updated SRID value, if required */ private Geometry setSRID(Geometry g, int SRID) { if (SRID != 0) g.setSRID(SRID); return g; }
/** * Sets the SRID, if it was specified in the WKB * * @param g the geometry to update * @return the geometry with an updated SRID value, if required */ private Geometry setSRID(Geometry g) { if (SRID != 0) g.setSRID(SRID); return g; }
public void setSRID(int SRID) { geometry.setSRID(SRID); }
@Override public void setGeometryValue( Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException { if (g == null || g.isEmpty()) { ps.setNull(column, Types.BLOB); } else { g.setSRID(srid); try { ps.setBytes(column, new GeoPkgGeomWriter(dimension, geomWriterConfig).write(g)); } catch (IOException e) { throw new RuntimeException(e); } } }
protected Geometry read() throws IOException { // header must be read! // read the geometry try { WKBReader wkbReader = new WKBReader(factory); Geometry g = wkbReader.read(input); g.setSRID(header.getSrid()); return g; } catch (ParseException e) { throw new IOException(e); } }
private static Geometry fromWKB(byte[] wkb) { try { ByteArrayInputStream bytes = new ByteArrayInputStream(wkb, 0, wkb.length - 4); // read the geometry Geometry g = new WKBReader().read(new InputStreamInStream(bytes)); // read the srid int srid = 0; srid |= wkb[wkb.length - 4] & 0xFF; srid <<= 8; srid |= wkb[wkb.length - 3] & 0xFF; srid <<= 8; srid |= wkb[wkb.length - 2] & 0xFF; srid <<= 8; srid |= wkb[wkb.length - 1] & 0xFF; g.setSRID(srid); return g; } catch (Exception e) { throw new RuntimeException(e); } }
finalSimplifiedFootprint = JTS.transform(simplifiedFootprintGeometry, transform); } else { simplifiedFootprintGeometry.setSRID(NO_SRID); finalSimplifiedFootprint = simplifiedFootprintGeometry; if (footprintCoordinates == FootprintCoordinates.MODEL_SPACE) { if (srid != null) { simplifiedFootprintGeometry.setSRID(srid); simplifiedFootprintGeometry.setSRID(NO_SRID);
/** * Reads a geometry from its well known text representation, specifying an srid. * * @param wkt The well known text of the geometry. * @param srid The srid of the geometry * @return An array of bytes representing the geometry. */ public static byte[] GeomFromText(String wkt, int srid) { if (wkt == null) { return null; } WKTReader reader = new WKTReader(); try { Geometry g = reader.read(wkt); g.setSRID(srid); return toWKB(g); } catch (ParseException e) { throw new RuntimeException(e); } }
/** * Compute the footprint. * * @param geometriesList the List of all the geometries found across the dataset * @param transform * @throws MismatchedDimensionException * @throws TransformException * @throws FactoryException */ private void computeFootprint(List<Polygon> geometriesList, MathTransform transform) throws MismatchedDimensionException, TransformException, FactoryException { // Creating the final multipolygon Polygon[] polArray = new Polygon[geometriesList.size()]; Polygon[] polygons = geometriesList.toArray(polArray); final Geometry innerGeometry = new MultiPolygon(polygons, GF); if (footprintCoordinates == FootprintCoordinates.MODEL_SPACE) { this.footprint = JTS.transform(innerGeometry, transform); } else { this.footprint = innerGeometry; innerGeometry.setSRID(NO_SRID); } // Compute the ROIShape if (!innerGeometry.isEmpty()) { LiteShape2 shape = new LiteShape2(innerGeometry, TRANSLATED_TX, null, false); roiShape = (ROIShape) new ROIShape(shape); } }
public Geometry read(InStream is) throws IOException { parse(is); readCoordinateSequences(); Type type = getTypeFromBinary(); Geometry geometry = decode(0, type); geometry.setSRID(binary.getSrid()); return geometry; }
/** * Sets the SRID, if it was specified in the WKB * * @param g the geometry to update * @return the geometry with an updated SRID value, if required */ private Geometry setSRID(Geometry g, int SRID) { if (SRID != 0) g.setSRID(SRID); return g; }
public static Geometry gFromWKT( String wkt, int srid ) { try { Geometry g = wktreader().read( wkt ); g.setSRID(srid); return g; } catch (ParseException e) { throw new IllegalArgumentException(e); } }
public static Geometry gFromWKT( String wkt, int srid ) { try { Geometry g = wktreader().read( wkt ); g.setSRID(srid); return g; } catch (ParseException e) { throw new IllegalArgumentException(e); } }
/** * Sets the SRID on a geometry to a particular integer value. */ public static byte[] ST_SetSRID ( byte[] wkb, int srid ) { if ( wkb == null ) { return null; } Geometry g = gFromWKB(wkb); g.setSRID(srid); return gToWKB(g); }
@Override public MultiPolygon unmarshal(String val) throws ParseException { WKTReader wktReader = new WKTReader(); Geometry the_geom = wktReader.read(val); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); try { return (MultiPolygon) the_geom; } catch (ClassCastException e) { throw new ParseException("WKT val is a " + the_geom.getClass().getName()); } }
@Override public String marshal(G the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Geometry obj is null."); } } }
@Override public String marshal(G the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Geometry obj is null."); } } }
@Override public Polygon unmarshal(String val) throws ParseException { WKTReader wktReader = new WKTReader(); Geometry the_geom = wktReader.read(val); if (the_geom instanceof Polygon) { if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return (Polygon) the_geom; } throw new ParseException("WKB val is not a Polygon."); }
public void testCreateSchemaUTMCRS() throws Exception { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(tname("ft2")); builder.setNamespaceURI(dataStore.getNamespaceURI()); builder.setCRS(getUTMCRS()); builder.add(aname("geometry"), Point.class); builder.add(aname("intProperty"), Integer.class); builder.add(aname("stringProperty"), String.class); SimpleFeatureType featureType = builder.buildFeatureType(); dataStore.createSchema(featureType); SimpleFeatureType ft2 = dataStore.getSchema(tname("ft2")); assertNotNull(ft2); try (FeatureWriter w = dataStore.getFeatureWriter(tname("ft2"), Transaction.AUTO_COMMIT)) { w.hasNext(); // write out a feature with a geomety in teh srs, basically accomodate databases that // have // to query the first feature in order to get the srs for the feature type SimpleFeature f = (SimpleFeature) w.next(); Geometry g = new WKTReader().read("POINT(593493 4914730)"); g.setSRID(26713); f.setAttribute(0, g); f.setAttribute(1, Integer.valueOf(0)); f.setAttribute(2, "hello"); w.write(); } // clear out the feature type cache dataStore.getEntry(new NameImpl(dataStore.getNamespaceURI(), tname("ft2"))).dispose(); ft2 = dataStore.getSchema(tname("ft2")); assertTrue(CRS.equalsIgnoreMetadata(getUTMCRS(), ft2.getCoordinateReferenceSystem())); }
private void checkCopy(final Geometry g) { int SRID = 123; g.setSRID(SRID ); Object DATA = new Integer(999); g.setUserData(DATA); Geometry copy = g.copy(); assertEquals(g.getSRID(), copy.getSRID()); assertEquals(g.getUserData(), copy.getUserData()); //TODO: use a test which checks all ordinates of CoordinateSequences assertTrue( g.equalsExact(copy) ); } }