[Schmitzm-commits] r1330 - in trunk: src/schmitzm/geotools src/schmitzm/geotools/io src_junit/schmitzm/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Dec 6 23:14:37 CET 2010
Author: alfonx
Date: 2010-12-06 23:14:36 +0100 (Mon, 06 Dec 2010)
New Revision: 1330
Modified:
trunk/src/schmitzm/geotools/GTUtil.java
trunk/src/schmitzm/geotools/io/GeoExportUtil.java
trunk/src_junit/schmitzm/geotools/GTUtilTest.java
Log:
Added GTUtil.getEPSG(CRS crs) whoch returns the "EPSG:????" or null for a CRS
Modified: trunk/src/schmitzm/geotools/GTUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/GTUtil.java 2010-12-06 14:44:38 UTC (rev 1329)
+++ trunk/src/schmitzm/geotools/GTUtil.java 2010-12-06 22:14:36 UTC (rev 1330)
@@ -35,7 +35,6 @@
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -59,6 +58,7 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.geometry.Envelope;
+import org.opengis.metadata.Identifier;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
@@ -93,8 +93,11 @@
/** Konstante fuer das CRS "WGS84" (erzeugt als "EPSG:4326") */
public static CoordinateReferenceSystem WGS84 = null;
-
- /** Konstante fuer das CRS "EPSG:3785". Ein welt umspannendens CRS in Metern. http://spatialreference.org/ref/epsg/3785/ */
+
+ /**
+ * Konstante fuer das CRS "EPSG:3785". Ein welt umspannendens CRS in Metern.
+ * http://spatialreference.org/ref/epsg/3785/
+ */
public static CoordinateReferenceSystem WORLD_METER = null;
private static HashMap<Object, Object> defaultRendererHints;
@@ -104,17 +107,18 @@
try {
WGS84 = CRS.decode("EPSG:4326", true); // lat/lon (WGS84)
} catch (Exception err) {
- LOGGER
- .warn("Exception while creating default WGS84 from code 'EPSG:4326'",err);
+ LOGGER.warn(
+ "Exception while creating default WGS84 from code 'EPSG:4326'",
+ err);
}
try {
- WORLD_METER = CRS.decode("EPSG:3785", true);
+ WORLD_METER = CRS.decode("EPSG:3785", true);
} catch (Exception err) {
- LOGGER
- .warn("Exception while creating CRS from code 'EPSG:3785'",err);
+ LOGGER.warn("Exception while creating CRS from code 'EPSG:3785'",
+ err);
}
-
+
}
/**
@@ -183,8 +187,8 @@
*/
public static Envelope2D createEnvelope2D(Rectangle2D env,
CoordinateReferenceSystem crs) {
- return new Envelope2D(crs, env.getX(), env.getY(), env.getWidth(), env
- .getHeight());
+ return new Envelope2D(crs, env.getX(), env.getY(), env.getWidth(),
+ env.getHeight());
}
/**
@@ -192,12 +196,12 @@
* {@linkplain CoordinateReferenceSystem CRS} fuer eine Authority.
*
* @param authority
- * Authority fuer die die CRS geliefert werden (z.B. {@code
- * "EPSG"})
+ * Authority fuer die die CRS geliefert werden (z.B.
+ * {@code "EPSG"})
* @param longitudeFirst
* {@code true} erzwingt die Achsenordnung (longitude, latitude).
- * Siehe {@link CRS#decode(String, boolean)} (Bemerkung: {@code
- * false} bedeutet System-Default, <b>nicht</b> (latitude,
+ * Siehe {@link CRS#decode(String, boolean)} (Bemerkung:
+ * {@code false} bedeutet System-Default, <b>nicht</b> (latitude,
* longitude)!)
* @param suppressWarnings
* wenn {@code true} werden Warnmeldungen unterdrueckt
@@ -220,12 +224,12 @@
* {@linkplain CoordinateReferenceSystem CRS} fuer eine Authority.
*
* @param authority
- * Authority fuer die die CRS geliefert werden (z.B. {@code
- * "EPSG"})
+ * Authority fuer die die CRS geliefert werden (z.B.
+ * {@code "EPSG"})
* @param longitudeFirst
* {@code true} erzwingt die Achsenordnung (longitude, latitude).
- * Siehe {@link CRS#decode(String, boolean)} (Bemerkung: {@code
- * false} bedeutet System-Default, <b>nicht</b> (latitude,
+ * Siehe {@link CRS#decode(String, boolean)} (Bemerkung:
+ * {@code false} bedeutet System-Default, <b>nicht</b> (latitude,
* longitude)!)
* @param suppressWarnings
* wenn {@code true} werden Warnmeldungen unterdrueckt
@@ -234,7 +238,7 @@
public static final SortedMap<String, CoordinateReferenceSystem> getAvailableCRSByCode(
String authority, boolean longitudeFirst, boolean suppressWarnings) {
TreeMap<String, CoordinateReferenceSystem> map = new TreeMap<String, CoordinateReferenceSystem>();
- for (String code : (Set<String>) CRS.getSupportedCodes(authority)) {
+ for (String code : CRS.getSupportedCodes(authority)) {
if (!code.startsWith(authority))
code = authority + ":" + code;
try {
@@ -378,21 +382,20 @@
defaultRendererHints.put(
StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
StreamingRenderer.SCALE_OGC);
-// defaultRendererHints.put(
-// StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
-// StreamingRenderer.SCALE_ACCURATE);
-
+ // defaultRendererHints.put(
+ // StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
+ // StreamingRenderer.SCALE_ACCURATE);
defaultRendererHints.put(StreamingRenderer.OPTIMIZE_FTS_RENDERING_KEY,
Boolean.TRUE);
-//
-// if (renderer instanceof ShapefileRenderer) {
-// defaultRendererHints.put(StreamingRenderer.MEMORY_PRE_LOADING_KEY,
-// Boolean.TRUE);
-// } else {
-// defaultRendererHints.put(StreamingRenderer.MEMORY_PRE_LOADING_KEY,
-// Boolean.FALSE);
-// }
+ //
+ // if (renderer instanceof ShapefileRenderer) {
+ // defaultRendererHints.put(StreamingRenderer.MEMORY_PRE_LOADING_KEY,
+ // Boolean.TRUE);
+ // } else {
+ // defaultRendererHints.put(StreamingRenderer.MEMORY_PRE_LOADING_KEY,
+ // Boolean.FALSE);
+ // }
defaultRendererHints.put(StreamingRenderer.OPTIMIZED_DATA_LOADING_KEY,
Boolean.TRUE);
@@ -454,15 +457,13 @@
}
} catch (FactoryException e) {
- LOGGER
- .warn(
- "Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
- e);
+ LOGGER.warn(
+ "Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
+ e);
} catch (TransformException e) {
- LOGGER
- .warn(
- "Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
- e);
+ LOGGER.warn(
+ "Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
+ e);
}
if (result == null) {
@@ -489,39 +490,59 @@
*/
public static void initEPSG() throws FactoryException, TransformException,
IOException {
-
+
// This action may take some time, and we never want it to happen on the
// Swing Thread
-// AVUtil.checkThatWeAreNotOnEDT();
-
+ // AVUtil.checkThatWeAreNotOnEDT();
+
URL epsgUrl = GTUtil.class
.getResource("/schmitzm/geotools/epsg.properties");
-
+
// you may try several locations...
Hints hints = new Hints(Hints.CRS_AUTHORITY_FACTORY,
PropertyAuthorityFactory.class);
ReferencingFactoryContainer referencingFactoryContainer = ReferencingFactoryContainer
.instance(hints);
-
+
PropertyAuthorityFactory factory = new PropertyAuthorityFactory(
referencingFactoryContainer, Citations.fromName("EPSG"),
epsgUrl);
ReferencingFactoryFinder.addAuthorityFactory(factory);
ReferencingFactoryFinder.scanForPlugins(); // hook everything up
-
+
final CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
-
+
// 900913 comes from the .properties file and is an unofficial EPSG code
// by Google
final CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:900913");
-
- final com.vividsolutions.jts.geom.Envelope envelope = new com.vividsolutions.jts.geom.Envelope(0, 10, 0, 10);
+
+ final com.vividsolutions.jts.geom.Envelope envelope = new com.vividsolutions.jts.geom.Envelope(
+ 0, 10, 0, 10);
final MathTransform transform = CRS.findMathTransform(sourceCRS,
targetCRS, true);
-
+
@SuppressWarnings("unused")
- final com.vividsolutions.jts.geom.Envelope result = JTS.transform(envelope, transform);
-
+ final com.vividsolutions.jts.geom.Envelope result = JTS.transform(
+ envelope, transform);
+
}
+ /**
+ * Tries to determin the EPSG:XXXX definition of a CRS.
+ */
+ public static String getEPSG(CoordinateReferenceSystem crs) {
+ if (!crs.getIdentifiers().isEmpty()) {
+ Object next = crs.getIdentifiers().iterator().next();
+ if (next instanceof Identifier) {
+ Identifier identifier = (Identifier) next;
+ if (identifier.getAuthority().getTitle().toString()
+ .equals("European Petroleum Survey Group")
+ || identifier.toString().startsWith("EPSG:")) {
+ return "EPSG:" + identifier.getCode();
+ }
+ }
+ }
+ return null;
+ }
+
}
Modified: trunk/src/schmitzm/geotools/io/GeoExportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoExportUtil.java 2010-12-06 14:44:38 UTC (rev 1329)
+++ trunk/src/schmitzm/geotools/io/GeoExportUtil.java 2010-12-06 22:14:36 UTC (rev 1330)
@@ -50,11 +50,11 @@
import org.geotools.gce.arcgrid.ArcGridWriter;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.metadata.Identifier;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import schmitzm.data.WritableGridRaster;
+import schmitzm.geotools.GTUtil;
import schmitzm.geotools.feature.FeatureCollectionReader;
import schmitzm.geotools.grid.GridUtil;
import schmitzm.io.IOUtil;
@@ -345,20 +345,10 @@
String whatToWrite = null;
/**
- * LetIf we can determine the EPSG code for this, let's save it as
- * "EPSG:12345" to the file.
+ * If we CAN determine the EPSG code for this, save it as "EPSG:????" to
+ * the file. This is easier for GS to load (i heard)
*/
- if (!crs.getIdentifiers().isEmpty()) {
- Object next = crs.getIdentifiers().iterator().next();
- if (next instanceof Identifier) {
- Identifier identifier = (Identifier) next;
- if (identifier.getAuthority().getTitle().toString()
- .equals("European Petroleum Survey Group")
- || identifier.toString().startsWith("EPSG:")) {
- whatToWrite = "EPSG:" + identifier.getCode();
- }
- }
- }
+ whatToWrite = GTUtil.getEPSG(crs);
if (whatToWrite == null) {
// If we don't know the EPSG code for the CRS, save it as WKT
Modified: trunk/src_junit/schmitzm/geotools/GTUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/GTUtilTest.java 2010-12-06 14:44:38 UTC (rev 1329)
+++ trunk/src_junit/schmitzm/geotools/GTUtilTest.java 2010-12-06 22:14:36 UTC (rev 1330)
@@ -1,5 +1,6 @@
package schmitzm.geotools;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
@@ -12,11 +13,20 @@
public class GTUtilTest {
@Test
- public void testInitEPSG() throws FactoryException, TransformException, IOException {
+ public void testInitEPSG() throws FactoryException, TransformException,
+ IOException {
GTUtil.initEPSG();
-
- assertNotNull("Normal EPSG can not be resolved!", CRS.decode("EPSG:4326"));
- assertNotNull("Extended EPSG from epsg.properties can not be resolved!", CRS.decode("EPSG:900913"));
+
+ assertNotNull("Normal EPSG can not be resolved!",
+ CRS.decode("EPSG:4326"));
+ assertNotNull(
+ "Extended EPSG from epsg.properties can not be resolved!",
+ CRS.decode("EPSG:900913"));
}
+ @Test
+ public void testGetEPSG() {
+ assertEquals("EPSG:4326", GTUtil.getEPSG(GTUtil.WGS84));
+ }
+
}
More information about the Schmitzm-commits
mailing list