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

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

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

Geometry.getSRID介绍

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

JTS supports Spatial Reference System information in the simple way defined in the SFS. A Spatial Reference System ID (SRID) is present in each Geometry object. Geometry provides basic accessor operations for this field, but no others. The SRID is represented as an integer.
[中]返回Geometry使用的空间参照系统的ID。
JTS以SFS中定义的简单方式支持空间参考系统信息。每个Geometry对象中都有一个空间参考系统ID(SRID)。Geometry提供此字段的基本访问器操作,但不提供其他操作。SRID表示为一个整数。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

  1. /**
  2. * Two geometries are equal iff both have the same SRID, or both are unknown (i.e. a SRID of 0 or -1).
  3. *
  4. * @param geom1
  5. * @param geom2
  6. *
  7. * @return
  8. */
  9. private boolean equalSRID(Geometry geom1, Geometry geom2) {
  10. return geom1.getSRID() == geom2.getSRID() ||
  11. ( geom1.getSRID() < 1 && geom2.getSRID() < 1 );
  12. }

代码示例来源:origin: com.h2database/h2

  1. private static byte[] convertToWKB(Geometry g) {
  2. boolean includeSRID = g.getSRID() != 0;
  3. int dimensionCount = getDimensionCount(g);
  4. WKBWriter writer = new WKBWriter(dimensionCount, includeSRID);
  5. return writer.write(g);
  6. }

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

  1. public int getSRID() {
  2. return geometry.getSRID();
  3. }

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

  1. /**
  2. * Returns geometry SRID.
  3. *
  4. * <p>SRID code representing Spatial Reference System. SRID number used must be defined in the
  5. * Oracle MDSYS.CS_SRS table.
  6. *
  7. * <p><code>SRID_NULL</code>represents lack of coordinate system.
  8. *
  9. * @param geom Geometry SRID Number (JTS14 uses GeometryFactor.getSRID() )
  10. * @return <code>SRID</code> for provided geom
  11. */
  12. public static int SRID(Geometry geom) {
  13. return geom.getSRID();
  14. }

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

  1. /**
  2. * Used to convert double[] to SDO_ODINATE_ARRAY.
  3. *
  4. * <p>Will return <code>null</code> as an empty <code>SDO_GEOMETRY</code>
  5. *
  6. * @param geom Map to be represented as a STRUCT
  7. * @return STRUCT representing provided Map
  8. * @see net.refractions.jspatial.Converter#toDataType(java.lang.Object)
  9. */
  10. public STRUCT toSDO(Geometry geom) throws SQLException {
  11. return toSDO(geom, geom.getSRID());
  12. }

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

  1. private void initCRS(Geometry g) {
  2. // see if we have a native CRS in the mix
  3. if (crs == null && g.getUserData() instanceof CoordinateReferenceSystem) {
  4. crs = (CoordinateReferenceSystem) g.getUserData();
  5. }
  6. if (srid == -1 && g.getSRID() > 0) {
  7. srid = g.getSRID();
  8. }
  9. }
  10. }

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

  1. /**
  2. * Returns the spatial reference identifier for the geometry.
  3. *
  4. * <p>This method will return -1 if <tt>wkb</tt> is <code>null</code>.
  5. *
  6. * @param wkb The geometry.
  7. * @return The srid.
  8. */
  9. public static int GetSRID(byte[] wkb) {
  10. if (wkb == null) {
  11. return -1;
  12. }
  13. return fromWKB(wkb).getSRID();
  14. }

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

  1. @Override
  2. public Object visit(Literal expression, Object extraData) {
  3. Object value = expression.getValue();
  4. if (value instanceof Geometry) {
  5. Geometry g = (Geometry) value;
  6. if (g.getUserData() instanceof CoordinateReferenceSystem) {
  7. return g.getUserData();
  8. } else if (g.getSRID() > 0) {
  9. try {
  10. return CRS.decode("EPSG:" + g.getSRID());
  11. } catch (Exception e) {
  12. return null;
  13. }
  14. }
  15. }
  16. return null;
  17. }

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

  1. private static byte[] toWKB(Geometry g) {
  2. try {
  3. WKBWriter w = new WKBWriter();
  4. // write the geometry
  5. ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  6. w.write(g, new OutputStreamOutStream(bytes));
  7. // supplement it with the srid
  8. int srid = g.getSRID();
  9. bytes.write((byte) (srid >>> 24));
  10. bytes.write((byte) (srid >> 16 & 0xff));
  11. bytes.write((byte) (srid >> 8 & 0xff));
  12. bytes.write((byte) (srid & 0xff));
  13. return bytes.toByteArray();
  14. } catch (IOException e) {
  15. throw new RuntimeException(e);
  16. }
  17. }
  18. //

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

  1. if (userData != null && userData instanceof String) {
  2. srsName = (String) userData;
  3. } else if (geom.getSRID() > 0) {
  4. srsName = "EPSG:" + geom.getSRID();

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

  1. /**
  2. * Looks up the geometry srs by trying a number of heuristics. Returns -1 if all attempts at
  3. * guessing the srid failed.
  4. */
  5. protected int getGeometrySRID(Geometry g, AttributeDescriptor descriptor) throws IOException {
  6. int srid = getDescriptorSRID(descriptor);
  7. if (g == null) {
  8. return srid;
  9. }
  10. // check for srid in the jts geometry then
  11. if (srid <= 0 && g.getSRID() > 0) {
  12. srid = g.getSRID();
  13. }
  14. // check if the geometry has anything
  15. if (srid <= 0 && g.getUserData() instanceof CoordinateReferenceSystem) {
  16. // check for crs object
  17. CoordinateReferenceSystem crs = (CoordinateReferenceSystem) g.getUserData();
  18. try {
  19. Integer candidate = CRS.lookupEpsgCode(crs, false);
  20. if (candidate != null) srid = candidate;
  21. } catch (Exception e) {
  22. // ok, we tried...
  23. }
  24. }
  25. return srid;
  26. }

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

  1. private CoordinateReferenceSystem evaluateCRS(SimpleFeature originalFeature) {
  2. SimpleFeatureType originalSchema = originalFeature.getFeatureType();
  3. CoordinateReferenceSystem computedCRS = evaluateCRS(originalSchema);
  4. if (computedCRS == null) {
  5. // all right, let's try the sample feature then
  6. Geometry g = expression.evaluate(originalFeature, Geometry.class);
  7. if (g != null && g.getUserData() instanceof CoordinateReferenceSystem) {
  8. computedCRS = (CoordinateReferenceSystem) g.getUserData();
  9. } else {
  10. try {
  11. computedCRS = CRS.decode("EPSG:" + g.getSRID());
  12. } catch (Exception e) {
  13. return null;
  14. }
  15. }
  16. }
  17. return computedCRS;
  18. }

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

  1. if (crs == null && geometry.getSRID() > 0) {
  2. try {
  3. crs = CRS.decode("EPSG:" + geometry.getSRID());
  4. } catch (Exception e) {

代码示例来源:origin: org.n52.arctic-sea/shetland

  1. @Override
  2. public void setGeometry(final Geometry geometry) throws InvalidSridException {
  3. if (geometry != null && geometry.getSRID() == 0) {
  4. throw new InvalidSridException(0);
  5. }
  6. this.geometry = geometry;
  7. }

代码示例来源:origin: org.n52.arctic-sea/shetland

  1. public int getSRID() {
  2. if (this.envelope != null) {
  3. return envelope.getSrid();
  4. } else if (this.geometry != null) {
  5. return this.geometry.getSRID();
  6. } else {
  7. return -1;
  8. }
  9. }

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

  1. h.setVersion((byte) 0);
  2. h.setFlags(flags);
  3. h.setSrid(g.getSRID());
  4. if (config.isWriteEnvelope()) {
  5. h.setEnvelope(g.getEnvelopeInternal());
  6. ByteOrderValues.putInt(g.getSRID(), buf, order);
  7. out.write(buf, 4);

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

  1. private void writeGeometryType(int geometryType, Geometry g, OutStream os)
  2. throws IOException
  3. {
  4. int flag3D = (outputDimension == 3) ? 0x80000000 : 0;
  5. int typeInt = geometryType | flag3D;
  6. typeInt |= includeSRID ? 0x20000000 : 0;
  7. writeInt(typeInt, os);
  8. if (includeSRID) {
  9. writeInt(g.getSRID(), os);
  10. }
  11. }

代码示例来源:origin: org.n52.arctic-sea/shetland

  1. public static GeometryFactory getGeometryFactory(Geometry geometry) {
  2. if (geometry.getFactory().getSRID() > 0 || geometry.getSRID() == 0) {
  3. return geometry.getFactory();
  4. } else {
  5. return getGeometryFactoryForSRID(geometry.getSRID());
  6. }
  7. }

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

  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: 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. }

相关文章