org.locationtech.jts.geom.Geometry.setSRID()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中org.locationtech.jts.geom.Geometry.setSRID()方法的一些代码示例,展示了Geometry.setSRID()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.setSRID()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:setSRID

Geometry.setSRID介绍

[英]Sets the ID of the Spatial Reference System used by the Geometry.

NOTE: This method should only be used for exceptional circumstances or for backwards compatibility. Normally the SRID should be set on the GeometryFactory used to create the geometry. SRIDs set using this method will not be propagated to geometries returned by constructive methods.
[中]设置Geometry使用的空间参照系统的ID。
注意:此方法仅适用于特殊情况或向后兼容性。通常,应在用于创建几何图形的GeometryFactory上设置SRID。使用此方法设置的SRID不会传播到构造方法返回的几何体。

代码示例

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Sets the SRID, if it was specified in the WKB
  3. *
  4. * @param g the geometry to update
  5. * @return the geometry with an updated SRID value, if required
  6. */
  7. private Geometry setSRID(Geometry g, int SRID) {
  8. if (SRID != 0) g.setSRID(SRID);
  9. return g;
  10. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Sets the SRID, if it was specified in the WKB
  3. *
  4. * @param g the geometry to update
  5. * @return the geometry with an updated SRID value, if required
  6. */
  7. private Geometry setSRID(Geometry g) {
  8. if (SRID != 0) g.setSRID(SRID);
  9. return g;
  10. }

代码示例来源:origin: geotools/geotools

  1. public void setSRID(int SRID) {
  2. geometry.setSRID(SRID);
  3. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public void setGeometryValue(
  3. Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
  4. throws SQLException {
  5. if (g == null || g.isEmpty()) {
  6. ps.setNull(column, Types.BLOB);
  7. } else {
  8. g.setSRID(srid);
  9. try {
  10. ps.setBytes(column, new GeoPkgGeomWriter(dimension, geomWriterConfig).write(g));
  11. } catch (IOException e) {
  12. throw new RuntimeException(e);
  13. }
  14. }
  15. }

代码示例来源:origin: geotools/geotools

  1. protected Geometry read() throws IOException { // header must be read!
  2. // read the geometry
  3. try {
  4. WKBReader wkbReader = new WKBReader(factory);
  5. Geometry g = wkbReader.read(input);
  6. g.setSRID(header.getSrid());
  7. return g;
  8. } catch (ParseException e) {
  9. throw new IOException(e);
  10. }
  11. }

代码示例来源:origin: geotools/geotools

  1. private static Geometry fromWKB(byte[] wkb) {
  2. try {
  3. ByteArrayInputStream bytes = new ByteArrayInputStream(wkb, 0, wkb.length - 4);
  4. // read the geometry
  5. Geometry g = new WKBReader().read(new InputStreamInStream(bytes));
  6. // read the srid
  7. int srid = 0;
  8. srid |= wkb[wkb.length - 4] & 0xFF;
  9. srid <<= 8;
  10. srid |= wkb[wkb.length - 3] & 0xFF;
  11. srid <<= 8;
  12. srid |= wkb[wkb.length - 2] & 0xFF;
  13. srid <<= 8;
  14. srid |= wkb[wkb.length - 1] & 0xFF;
  15. g.setSRID(srid);
  16. return g;
  17. } catch (Exception e) {
  18. throw new RuntimeException(e);
  19. }
  20. }

代码示例来源:origin: geotools/geotools

  1. finalSimplifiedFootprint = JTS.transform(simplifiedFootprintGeometry, transform);
  2. } else {
  3. simplifiedFootprintGeometry.setSRID(NO_SRID);
  4. finalSimplifiedFootprint = simplifiedFootprintGeometry;
  5. if (footprintCoordinates == FootprintCoordinates.MODEL_SPACE) {
  6. if (srid != null) {
  7. simplifiedFootprintGeometry.setSRID(srid);
  8. simplifiedFootprintGeometry.setSRID(NO_SRID);

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Reads a geometry from its well known text representation, specifying an srid.
  3. *
  4. * @param wkt The well known text of the geometry.
  5. * @param srid The srid of the geometry
  6. * @return An array of bytes representing the geometry.
  7. */
  8. public static byte[] GeomFromText(String wkt, int srid) {
  9. if (wkt == null) {
  10. return null;
  11. }
  12. WKTReader reader = new WKTReader();
  13. try {
  14. Geometry g = reader.read(wkt);
  15. g.setSRID(srid);
  16. return toWKB(g);
  17. } catch (ParseException e) {
  18. throw new RuntimeException(e);
  19. }
  20. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Compute the footprint.
  3. *
  4. * @param geometriesList the List of all the geometries found across the dataset
  5. * @param transform
  6. * @throws MismatchedDimensionException
  7. * @throws TransformException
  8. * @throws FactoryException
  9. */
  10. private void computeFootprint(List<Polygon> geometriesList, MathTransform transform)
  11. throws MismatchedDimensionException, TransformException, FactoryException {
  12. // Creating the final multipolygon
  13. Polygon[] polArray = new Polygon[geometriesList.size()];
  14. Polygon[] polygons = geometriesList.toArray(polArray);
  15. final Geometry innerGeometry = new MultiPolygon(polygons, GF);
  16. if (footprintCoordinates == FootprintCoordinates.MODEL_SPACE) {
  17. this.footprint = JTS.transform(innerGeometry, transform);
  18. } else {
  19. this.footprint = innerGeometry;
  20. innerGeometry.setSRID(NO_SRID);
  21. }
  22. // Compute the ROIShape
  23. if (!innerGeometry.isEmpty()) {
  24. LiteShape2 shape = new LiteShape2(innerGeometry, TRANSLATED_TX, null, false);
  25. roiShape = (ROIShape) new ROIShape(shape);
  26. }
  27. }

代码示例来源:origin: geotools/geotools

  1. public Geometry read(InStream is) throws IOException {
  2. parse(is);
  3. readCoordinateSequences();
  4. Type type = getTypeFromBinary();
  5. Geometry geometry = decode(0, type);
  6. geometry.setSRID(binary.getSrid());
  7. return geometry;
  8. }

代码示例来源:origin: locationtech/jts

  1. /**
  2. * Sets the SRID, if it was specified in the WKB
  3. *
  4. * @param g the geometry to update
  5. * @return the geometry with an updated SRID value, if required
  6. */
  7. private Geometry setSRID(Geometry g, int SRID)
  8. {
  9. if (SRID != 0)
  10. g.setSRID(SRID);
  11. return g;
  12. }

代码示例来源:origin: org.opengeo/geodb

  1. public static Geometry gFromWKT( String wkt, int srid ) {
  2. try {
  3. Geometry g = wktreader().read( wkt );
  4. g.setSRID(srid);
  5. return g;
  6. }
  7. catch (ParseException e) {
  8. throw new IllegalArgumentException(e);
  9. }
  10. }

代码示例来源:origin: jdeolive/geodb

  1. public static Geometry gFromWKT( String wkt, int srid ) {
  2. try {
  3. Geometry g = wktreader().read( wkt );
  4. g.setSRID(srid);
  5. return g;
  6. }
  7. catch (ParseException e) {
  8. throw new IllegalArgumentException(e);
  9. }
  10. }

代码示例来源:origin: org.opengeo/geodb

  1. /**
  2. * Sets the SRID on a geometry to a particular integer value.
  3. */
  4. public static byte[] ST_SetSRID ( byte[] wkb, int srid ) {
  5. if ( wkb == null ) {
  6. return null;
  7. }
  8. Geometry g = gFromWKB(wkb);
  9. g.setSRID(srid);
  10. return gToWKB(g);
  11. }

代码示例来源:origin: org.geoserver.geofence/geofence-model

  1. @Override
  2. public MultiPolygon unmarshal(String val) throws ParseException {
  3. WKTReader wktReader = new WKTReader();
  4. Geometry the_geom = wktReader.read(val);
  5. if (the_geom.getSRID() == 0)
  6. the_geom.setSRID(4326);
  7. try {
  8. return (MultiPolygon) the_geom;
  9. } catch (ClassCastException e) {
  10. throw new ParseException("WKT val is a " + the_geom.getClass().getName());
  11. }
  12. }

代码示例来源:origin: org.geoserver.geofence/geofence-model

  1. @Override
  2. public String marshal(G the_geom) throws ParseException {
  3. if (the_geom != null) {
  4. WKTWriter wktWriter = new WKTWriter();
  5. if (the_geom.getSRID() == 0)
  6. the_geom.setSRID(4326);
  7. return wktWriter.write(the_geom);
  8. } else {
  9. throw new ParseException("Geometry obj is null.");
  10. }
  11. }
  12. }

代码示例来源:origin: org.geoserver.geofence/geofence-model-internal

  1. @Override
  2. public String marshal(G the_geom) throws ParseException {
  3. if (the_geom != null) {
  4. WKTWriter wktWriter = new WKTWriter();
  5. if (the_geom.getSRID() == 0)
  6. the_geom.setSRID(4326);
  7. return wktWriter.write(the_geom);
  8. } else {
  9. throw new ParseException("Geometry obj is null.");
  10. }
  11. }
  12. }

代码示例来源:origin: geoserver/geofence

  1. @Override
  2. public Polygon unmarshal(String val) throws ParseException {
  3. WKTReader wktReader = new WKTReader();
  4. Geometry the_geom = wktReader.read(val);
  5. if (the_geom instanceof Polygon) {
  6. if (the_geom.getSRID() == 0)
  7. the_geom.setSRID(4326);
  8. return (Polygon) the_geom;
  9. }
  10. throw new ParseException("WKB val is not a Polygon.");
  11. }

代码示例来源:origin: geotools/geotools

  1. public void testCreateSchemaUTMCRS() throws Exception {
  2. SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
  3. builder.setName(tname("ft2"));
  4. builder.setNamespaceURI(dataStore.getNamespaceURI());
  5. builder.setCRS(getUTMCRS());
  6. builder.add(aname("geometry"), Point.class);
  7. builder.add(aname("intProperty"), Integer.class);
  8. builder.add(aname("stringProperty"), String.class);
  9. SimpleFeatureType featureType = builder.buildFeatureType();
  10. dataStore.createSchema(featureType);
  11. SimpleFeatureType ft2 = dataStore.getSchema(tname("ft2"));
  12. assertNotNull(ft2);
  13. try (FeatureWriter w = dataStore.getFeatureWriter(tname("ft2"), Transaction.AUTO_COMMIT)) {
  14. w.hasNext();
  15. // write out a feature with a geomety in teh srs, basically accomodate databases that
  16. // have
  17. // to query the first feature in order to get the srs for the feature type
  18. SimpleFeature f = (SimpleFeature) w.next();
  19. Geometry g = new WKTReader().read("POINT(593493 4914730)");
  20. g.setSRID(26713);
  21. f.setAttribute(0, g);
  22. f.setAttribute(1, Integer.valueOf(0));
  23. f.setAttribute(2, "hello");
  24. w.write();
  25. }
  26. // clear out the feature type cache
  27. dataStore.getEntry(new NameImpl(dataStore.getNamespaceURI(), tname("ft2"))).dispose();
  28. ft2 = dataStore.getSchema(tname("ft2"));
  29. assertTrue(CRS.equalsIgnoreMetadata(getUTMCRS(), ft2.getCoordinateReferenceSystem()));
  30. }

代码示例来源:origin: locationtech/jts

  1. private void checkCopy(final Geometry g) {
  2. int SRID = 123;
  3. g.setSRID(SRID );
  4. Object DATA = new Integer(999);
  5. g.setUserData(DATA);
  6. Geometry copy = g.copy();
  7. assertEquals(g.getSRID(), copy.getSRID());
  8. assertEquals(g.getUserData(), copy.getUserData());
  9. //TODO: use a test which checks all ordinates of CoordinateSequences
  10. assertTrue( g.equalsExact(copy) );
  11. }
  12. }

相关文章