本文整理了Java中org.geotools.referencing.CRS.lookupEpsgCode()
方法的一些代码示例,展示了CRS.lookupEpsgCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRS.lookupEpsgCode()
方法的具体详情如下:
包路径:org.geotools.referencing.CRS
类名称:CRS
方法名:lookupEpsgCode
[英]Looks up an EPSG code for the given CoordinateReferenceSystem). This is a convenience method for #lookupIdentifier(Citations,IdentifiedObject,boolean)( Citations#EPSG, crs, fullScan)
except that code is parsed as an integer.
[中]查找给定坐标引用系统的EPSG代码)。这是#lookupIdentifier(Citations,IdentifiedObject,boolean)( Citations#EPSG, crs, fullScan)
的一种方便方法,只是代码被解析为整数。
代码示例来源:origin: geoserver/geoserver
@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);
}
代码示例来源:origin: geoserver/geoserver
Integer code = CRS.lookupEpsgCode(crs, extensive);
if (code != null) ftinfo.setSRS("EPSG:" + code);
} catch (FactoryException e) {
代码示例来源:origin: geoserver/geoserver
Integer code = CRS.lookupEpsgCode(nativeCRS, false);
if (code != null) {
cinfo.setSRS("EPSG:" + code);
代码示例来源:origin: geoserver/geoserver
@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));
}
代码示例来源:origin: geoserver/geoserver
Integer code = CRS.lookupEpsgCode(nativeCRS, false);
if (code != null) {
cinfo.setSRS("EPSG:" + code);
代码示例来源:origin: geotools/geotools
static Integer findSRID(GridCoverage2D raster) throws Exception {
return CRS.lookupEpsgCode(raster.getCoordinateReferenceSystem(), true);
}
代码示例来源:origin: geotools/geotools
static Integer findSRID(ReferencedEnvelope e) throws Exception {
return CRS.lookupEpsgCode(e.getCoordinateReferenceSystem(), true);
}
代码示例来源:origin: geotools/geotools
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;
}
}
代码示例来源:origin: geotools/geotools
/**
* 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;
}
代码示例来源:origin: geotools/geotools
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;
}
代码示例来源:origin: geotools/geotools
Integer epsgCode = CRS.lookupEpsgCode(crs, false);
if (epsgCode == null) {
throw new IllegalArgumentException(
代码示例来源:origin: geotools/geotools
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;
}
代码示例来源:origin: geotools/geotools
@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));
}
代码示例来源:origin: geotools/geotools
CoordinateReferenceSystem crs = (CoordinateReferenceSystem) g.getUserData();
try {
Integer code = CRS.lookupEpsgCode(crs, false);
if (code != null) {
ai.addAttribute("", "srsName", "", "anyURI", "EPSG:" + code);
代码示例来源:origin: geotools/geotools
gc.setSRID(CRS.lookupEpsgCode(crs, true));
} catch (FactoryException e) {
代码示例来源:origin: geotools/geotools
/** 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);
}
代码示例来源:origin: geotools/geotools
/**
* 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;
}
代码示例来源:origin: geotools/geotools
/** 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));
}
代码示例来源:origin: geotools/geotools
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));
}
代码示例来源:origin: geotools/geotools
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);
}
内容来源于网络,如有侵权,请联系作者删除!