@Override public String toString(Object obj) { CoordinateReferenceSystem crs = (CoordinateReferenceSystem) obj; try { Integer epsg = CRS.lookupEpsgCode(crs, false); if (epsg != null) { return "EPSG:" + epsg; } } catch (FactoryException e) { XStreamPersister.LOGGER.warning( "Could not determine epsg code of crs, encoding as WKT"); } return new CRSConverter().toString(crs); }
Integer code = CRS.lookupEpsgCode(crs, extensive); if (code != null) ftinfo.setSRS("EPSG:" + code); } catch (FactoryException e) {
Integer code = CRS.lookupEpsgCode(nativeCRS, false); if (code != null) { cinfo.setSRS("EPSG:" + code);
@Test public void testReprojectLayerGroup() throws NoSuchAuthorityCodeException, FactoryException, Exception { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); lg.getLayers().add(l); lg.getStyles().add(null); lg.setName("test-reproject"); // EPSG:4901 "equivalent" but different uom String wkt = "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]"; CoordinateReferenceSystem lCrs = CRS.parseWKT(wkt); ((FeatureTypeInfo) l.getResource()).setSRS(null); ((FeatureTypeInfo) l.getResource()).setNativeCRS(lCrs); assertNull(CRS.lookupEpsgCode(lCrs, false)); // Use the real thing now CoordinateReferenceSystem lgCrs = CRS.decode("EPSG:4901"); assertNotNull(CRS.lookupEpsgCode(lgCrs, false)); // Reproject our layer group to EPSG:4901. We expect it to have an EPSG code. cb.calculateLayerGroupBounds(lg, lgCrs); assertNotNull(CRS.lookupEpsgCode(lg.getBounds().getCoordinateReferenceSystem(), false)); }
Integer code = CRS.lookupEpsgCode(nativeCRS, false); if (code != null) { cinfo.setSRS("EPSG:" + code);
static Integer findSRID(GridCoverage2D raster) throws Exception { return CRS.lookupEpsgCode(raster.getCoordinateReferenceSystem(), true); }
static Integer findSRID(ReferencedEnvelope e) throws Exception { return CRS.lookupEpsgCode(e.getCoordinateReferenceSystem(), true); }
static DBObject encodeCRSToGeoJSON(CoordinateReferenceSystem crs) { if (crs == null) { return null; } Integer epsgCode = null; try { epsgCode = CRS.lookupEpsgCode(crs, true); } catch (FactoryException ignore) { } if (epsgCode == null) { return null; } DBObject crsDBO = new BasicDBObject(KEY_type, VALUE_name); crsDBO.put( KEY_properties, new BasicDBObject(KEY_name, PREFIX_URN_OGC + "EPSG:" + epsgCode)); return crsDBO; } }
/** * Computes the declared SRS of a layer based on the layer schema and the EPSG forcing flag * * @param schema * @return * @throws FactoryException * @throws NoSuchAuthorityCodeException */ private CoordinateReferenceSystem getDeclaredSRS(FeatureType schema) throws FactoryException { // compute the default SRS of the feature source CoordinateReferenceSystem declaredCRS = schema.getCoordinateReferenceSystem(); if (isEPSGAxisOrderForced()) { Integer code = CRS.lookupEpsgCode(declaredCRS, false); if (code != null) { declaredCRS = CRS.decode("urn:ogc:def:crs:EPSG::" + code); } } return declaredCRS; }
private static org.opengis.geometry.Envelope getCRSEnvelope(CoordinateReferenceSystem targetCRS) throws FactoryException, NoSuchAuthorityCodeException { if (targetCRS.getDomainOfValidity() == null) { Integer code = CRS.lookupEpsgCode(targetCRS, true); if (code != null) { CRS.decode("EPSG:" + code, CRS.getAxisOrder(targetCRS) != AxisOrder.NORTH_EAST); } } org.opengis.geometry.Envelope envelope = CRS.getEnvelope(targetCRS); return envelope; }
Integer epsgCode = CRS.lookupEpsgCode(crs, false); if (epsgCode == null) { throw new IllegalArgumentException(
static Integer findSRID(SimpleFeatureType schema) throws Exception { CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem(); if (crs == null) { GeometryDescriptor gd = findGeometryDescriptor(schema); crs = gd.getCoordinateReferenceSystem(); } return crs != null ? CRS.lookupEpsgCode(crs, true) : null; }
@Test public void testLookup() throws NoSuchAuthorityCodeException, FactoryException { CoordinateReferenceSystem crs = CRS.decode("EPSG:" + CODE); assertEquals(Integer.valueOf(CODE), CRS.lookupEpsgCode(crs, true)); assertEquals(Integer.valueOf(CODE), CRS.lookupEpsgCode(crs, false)); }
CoordinateReferenceSystem crs = (CoordinateReferenceSystem) g.getUserData(); try { Integer code = CRS.lookupEpsgCode(crs, false); if (code != null) { ai.addAttribute("", "srsName", "", "anyURI", "EPSG:" + code);
gc.setSRID(CRS.lookupEpsgCode(crs, true)); } catch (FactoryException e) {
/** Encodes the given geometry with no srsName attribute and forcing 2D */ public void encode(Geometry geometry) { String srsName = null; // see if we have a EPSG CRS attached to the geometry if (geometry.getUserData() instanceof CoordinateReferenceSystem) { try { CoordinateReferenceSystem crs = (CoordinateReferenceSystem) geometry.getUserData(); Integer code = CRS.lookupEpsgCode(crs, false); if (code != null) { if (AxisOrder.NORTH_EAST.equals(CRS.getAxisOrder(crs))) { srsName = "urn:ogc:def:crs:EPSG::" + code; } else { srsName = "EPSG:" + code; } } } catch (Exception e) { LOGGER.fine("Failed to encode the CoordinateReferenceSystem into a srsName"); } } encode(geometry, srsName); }
/** * Looks up the geometry srs by trying a number of heuristics. Returns -1 if all attempts at * guessing the srid failed. */ protected int getGeometrySRID(Geometry g, AttributeDescriptor descriptor) throws IOException { int srid = getDescriptorSRID(descriptor); if (g == null) { return srid; } // check for srid in the jts geometry then if (srid <= 0 && g.getSRID() > 0) { srid = g.getSRID(); } // check if the geometry has anything if (srid <= 0 && g.getUserData() instanceof CoordinateReferenceSystem) { // check for crs object CoordinateReferenceSystem crs = (CoordinateReferenceSystem) g.getUserData(); try { Integer candidate = CRS.lookupEpsgCode(crs, false); if (candidate != null) srid = candidate; } catch (Exception e) { // ok, we tried... } } return srid; }
/** Tests {@link CRS#lookupIdentifier}. */ public void testFind() throws FactoryException { CoordinateReferenceSystem crs = getED50("ED50"); assertEquals( "Should find without scan thanks to the name.", "EPSG:4230", CRS.lookupIdentifier(crs, false)); assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, false)); crs = getED50("ED50 with unknown name"); if (supportsED50QuickScan()) { assertEquals( "With scan allowed, should find the CRS.", "EPSG:4230", CRS.lookupIdentifier(crs, false)); assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, false)); } else { assertNull("Should not find the CRS without a scan.", CRS.lookupIdentifier(crs, false)); assertEquals(null, CRS.lookupEpsgCode(crs, false)); } assertEquals( "With scan allowed, should find the CRS.", "EPSG:4230", CRS.lookupIdentifier(crs, true)); assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, true)); }
public void testSchema() throws Exception { SimpleFeatureType schema = dataStore.getSchema(tname(getLine3d())); CoordinateReferenceSystem crs = schema.getGeometryDescriptor().getCoordinateReferenceSystem(); assertEquals(Integer.valueOf(getEpsgCode()), CRS.lookupEpsgCode(crs, false)); assertEquals( getNativeSRID(), schema.getGeometryDescriptor().getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID)); assertEquals( 3, schema.getGeometryDescriptor().getUserData().get(Hints.COORDINATE_DIMENSION)); }
public void testSchema() throws Exception { if (!isGeographySupportAvailable()) { return; } SimpleFeatureType ft = dataStore.getFeatureSource(tname("geopoint")).getSchema(); assertNotNull(ft); assertTrue(ft.getDescriptor(aname("geo")) instanceof GeometryDescriptor); assertEquals(Point.class, ft.getDescriptor("geo").getType().getBinding()); int epsg = CRS.lookupEpsgCode( ((GeometryDescriptor) ft.getDescriptor(aname("geo"))) .getCoordinateReferenceSystem(), false); assertEquals(4326, epsg); }