Changeset 28191 in osm for applications/editors/josm/plugins/opendata/src/org
- Timestamp:
- 2012-04-05T01:59:36+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata
- Files:
-
- 12 added
- 12 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
r28143 r28191 50 50 import org.openstreetmap.josm.plugins.opendata.core.io.XmlImporter; 51 51 import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipImporter; 52 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GmlImporter; 52 53 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmlKmzImporter; 53 54 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.MifTabImporter; … … 79 80 for (AbstractImporter importer : Arrays.asList(new AbstractImporter[]{ 80 81 new CsvImporter(), new OdsImporter(), new XlsImporter(), // Tabular file formats 81 new KmlKmzImporter(), new ShpImporter(), new MifTabImporter(), // Geographic file formats 82 new KmlKmzImporter(), new ShpImporter(), new MifTabImporter(), new GmlImporter(), // Geographic file formats 82 83 new ZipImporter(), // Archive containing any of the others 83 84 xmlImporter = new XmlImporter() // Generic importer for XML files (currently used for Neptune files) -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r28152 r28191 96 96 public static final String KML_EXT = "kml"; 97 97 public static final String KMZ_EXT = "kmz"; 98 public static final String GML_EXT = "gml"; 98 99 public static final String XLS_EXT = "xls"; 99 100 public static final String ODS_EXT = "ods"; … … 121 122 public static final ExtensionFileFilter MIF_TAB_FILE_FILTER = new ExtensionFileFilter(MIF_EXT+","+TAB_EXT, MIF_EXT, tr("MapInfo files") + " (*."+MIF_EXT+",*."+TAB_EXT+")"); 122 123 public static final ExtensionFileFilter KML_KMZ_FILE_FILTER = new ExtensionFileFilter(KML_EXT+","+KMZ_EXT, KMZ_EXT, tr("KML/KMZ files") + " (*."+KML_EXT+",*."+KMZ_EXT+")"); 124 public static final ExtensionFileFilter GML_FILE_FILTER = new ExtensionFileFilter(GML_EXT, GML_EXT, tr("GML files") + " (*."+GML_EXT+")"); 123 125 public static final ExtensionFileFilter ZIP_FILE_FILTER = new ExtensionFileFilter(ZIP_EXT, ZIP_EXT, tr("Zip Files") + " (*."+ZIP_EXT+")"); 124 126 public static final ExtensionFileFilter XML_FILE_FILTER = new ExtensionFileFilter(XML_EXT, XML_EXT, tr("OpenData XML files") + " (*."+XML_EXT+")"); … … 142 144 143 145 /** 144 * KML tags145 */146 public static final String KML_PLACEMARK = "Placemark";147 public static final String KML_NAME = "name";148 public static final String KML_COLOR = "color";149 public static final String KML_SIMPLE_DATA = "SimpleData";150 public static final String KML_LINE_STRING = "LineString";151 public static final String KML_POINT = "Point";152 public static final String KML_POLYGON = "Polygon";153 public static final String KML_OUTER_BOUND = "outerBoundaryIs";154 public static final String KML_INNER_BOUND = "innerBoundaryIs";155 public static final String KML_LINEAR_RING = "LinearRing";156 public static final String KML_COORDINATES = "coordinates";157 158 /**159 146 * Resources 160 147 */ -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r28113 r28191 34 34 import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultZipHandler; 35 35 import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipHandler; 36 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultGmlHandler; 36 37 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultShpHandler; 38 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GmlHandler; 37 39 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpHandler; 38 40 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.CsvHandler; … … 87 89 setZipHandler(new DefaultZipHandler()); 88 90 setCsvHandler(new DefaultCsvHandler()); 91 setGmlHandler(new DefaultGmlHandler()); 89 92 } 90 93 … … 428 431 } 429 432 433 // --------- GML handling --------- 434 435 private GmlHandler gmlHandler; 436 437 public final void setGmlHandler(GmlHandler handler) { 438 gmlHandler = handler; 439 } 440 441 public final GmlHandler getGmlHandler() { 442 return gmlHandler; 443 } 444 430 445 // ------------ Zip handling ------------ 431 446 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchShpHandler.java
r28152 r28191 20 20 import org.geotools.referencing.operation.projection.MapProjection.AbstractProvider; 21 21 import org.opengis.referencing.FactoryException; 22 import org.opengis.referencing.NoSuchAuthorityCodeException; 22 23 import org.opengis.referencing.crs.CoordinateReferenceSystem; 23 24 import org.opengis.referencing.crs.ProjectedCRS; … … 28 29 public class FrenchShpHandler extends DefaultShpHandler { 29 30 31 @Override 32 public CoordinateReferenceSystem getCrsFor(String crsName) throws NoSuchAuthorityCodeException, FactoryException { 33 if (crsName.equalsIgnoreCase("RGM04")) { 34 return CRS.decode("EPSG:4471"); 35 } else if (crsName.equalsIgnoreCase("RGFG95_UTM_Zone_22N")) { 36 return CRS.decode("EPSG:2972"); 37 } else { 38 return super.getCrsFor(crsName); 39 } 40 } 41 30 42 /* (non-Javadoc) 31 43 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#findMathTransform(org.opengis.referencing.crs.CoordinateReferenceSystem, org.opengis.referencing.crs.CoordinateReferenceSystem, boolean) … … 34 46 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 35 47 throws FactoryException { 36 if (sourceCRS.getName().getCode().equalsIgnoreCase("RGM04")) { 37 return CRS.findMathTransform(CRS.decode("EPSG:4471"), targetCRS, lenient); 38 } else if (sourceCRS.getName().getCode().equalsIgnoreCase("RGFG95_UTM_Zone_22N")) { 39 return CRS.findMathTransform(CRS.decode("EPSG:2972"), targetCRS, lenient); 40 } else if (sourceCRS.getName().getCode().equalsIgnoreCase("Lambert I Nord")) { 48 if (sourceCRS.getName().getCode().equalsIgnoreCase("Lambert I Nord")) { 41 49 if (sourceCRS instanceof ProjectedCRS) { 42 50 GeodeticDatum datum = ((ProjectedCRS) sourceCRS).getDatum(); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/AskLicenseAgreementDialog.java
r28114 r28191 1 // JOSM opendata plugin. 2 // Copyright (C) 2011-2012 Don-vip 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 1 16 package org.openstreetmap.josm.plugins.opendata.core.gui; 2 17 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java
r28154 r28191 31 31 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 32 32 import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipReader; 33 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GmlReader; 33 34 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmlReader; 34 35 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmzReader; … … 115 116 } else if (filename.endsWith("."+TAB_EXT)) { 116 117 return TabReader.class; 118 } else if (filename.endsWith("."+GML_EXT)) { 119 return GmlReader.class; 117 120 } else if (filename.endsWith("."+ZIP_EXT)) { 118 121 return ZipReader.class; … … 167 170 } else if (readerClass.equals(XlsReader.class)) { 168 171 return XlsReader.parseDataSet(in, handler, instance); 172 } else if (readerClass.equals(GmlReader.class)) { 173 return GmlReader.parseDataSet(in, handler, instance); 169 174 } else { 170 175 throw new IllegalArgumentException("Unsupported reader class: "+readerClass.getName()); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r28154 r28191 39 39 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 40 40 import org.openstreetmap.josm.plugins.opendata.core.io.NeptuneReader; 41 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GmlReader; 41 42 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmlReader; 42 43 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmzReader; … … 133 134 // Test file name to see if it may contain useful data 134 135 for (String ext : new String[] { 135 CSV_EXT, KML_EXT, KMZ_EXT, XLS_EXT, ODS_EXT, SHP_EXT, MIF_EXT, TAB_EXT 136 CSV_EXT, KML_EXT, KMZ_EXT, XLS_EXT, ODS_EXT, SHP_EXT, MIF_EXT, TAB_EXT, GML_EXT 136 137 }) { 137 138 if (entry.getName().toLowerCase().endsWith("."+ext)) { … … 187 188 } else if (file.getName().toLowerCase().endsWith(TAB_EXT)) { 188 189 from = TabReader.parseDataSet(in, file, handler, instance); 190 } else if (file.getName().toLowerCase().endsWith(GML_EXT)) { 191 from = GmlReader.parseDataSet(in, handler, instance); 189 192 } else if (file.getName().toLowerCase().endsWith(XML_EXT)) { 190 193 if (OdPlugin.getInstance().xmlImporter.acceptFile(file)) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/AbstractMapInfoReader.java
r28000 r28191 1 // JOSM opendata plugin. 2 // Copyright (C) 2011-2012 Don-vip 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 1 16 package org.openstreetmap.josm.plugins.opendata.core.io.geographic; 2 17 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultShpHandler.java
r28152 r28191 32 32 import org.opengis.referencing.FactoryException; 33 33 import org.opengis.referencing.crs.CoordinateReferenceSystem; 34 import org.opengis.referencing.crs.GeographicCRS;35 34 import org.opengis.referencing.datum.GeodeticDatum; 36 35 import org.opengis.referencing.operation.MathTransform; … … 49 48 import org.openstreetmap.josm.tools.Pair; 50 49 51 public class DefaultShpHandler implements ShpHandler, OdConstants { 50 public class DefaultShpHandler extends DefaultGeographicHandler implements ShpHandler, OdConstants { 52 51 53 52 private static final List<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>> … … 70 69 } 71 70 72 private boolean useNodeMap = true;73 private boolean checkNodeProximity = false;74 private boolean preferMultipolygonToSimpleWay = false;75 71 private Charset dbfCharset = null; 76 72 77 73 @Override 78 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, 79 CoordinateReferenceSystem targetCRS, boolean lenient) 74 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 80 75 throws FactoryException { 81 if ( sourceCRS instanceof GeographicCRS &&sourceCRS.getName().getCode().equalsIgnoreCase("GCS_ETRS_1989")) {82 return CRS.findMathTransform( CRS.decode("EPSG:4258"), targetCRS, lenient);76 if (getCrsFor(sourceCRS.getName().getCode()) != null) { 77 return CRS.findMathTransform(getCrsFor(sourceCRS.getName().getCode()), targetCRS, lenient); 83 78 } else if (sourceCRS instanceof AbstractDerivedCRS && sourceCRS.getName().getCode().equalsIgnoreCase("Lambert_Conformal_Conic")) { 84 79 List<MathTransform> result = new ArrayList<MathTransform>(); … … 139 134 140 135 @Override 141 public boolean preferMultipolygonToSimpleWay() {142 return preferMultipolygonToSimpleWay;143 }144 145 @Override146 public void setPreferMultipolygonToSimpleWay(boolean prefer) {147 preferMultipolygonToSimpleWay = prefer;148 }149 150 @Override151 public boolean checkNodeProximity() {152 return checkNodeProximity;153 }154 155 @Override156 public void setCheckNodeProximity(boolean check) {157 checkNodeProximity = check;158 }159 160 @Override161 public void setUseNodeMap(boolean use) {162 useNodeMap = use;163 }164 165 @Override166 public boolean useNodeMap() {167 return useNodeMap;168 }169 170 @Override171 136 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives) { 172 137 // To be overriden by modules handlers -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeoCrsException.java
r28184 r28191 16 16 package org.openstreetmap.josm.plugins.opendata.core.io.geographic; 17 17 18 public class ShpCrsException extends Exception {18 public class GeoCrsException extends Exception { 19 19 20 public ShpCrsException() {20 public GeoCrsException() { 21 21 super(); 22 22 } 23 23 24 public ShpCrsException(String message, Throwable cause) {24 public GeoCrsException(String message, Throwable cause) { 25 25 super(message, cause); 26 26 } 27 27 28 public ShpCrsException(String message) {28 public GeoCrsException(String message) { 29 29 super(message); 30 30 } 31 31 32 public ShpCrsException(Throwable cause) {32 public GeoCrsException(Throwable cause) { 33 33 super(cause); 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeoMathTransformException.java
r28184 r28191 16 16 package org.openstreetmap.josm.plugins.opendata.core.io.geographic; 17 17 18 public class ShpMathTransformException extends Exception {18 public class GeoMathTransformException extends Exception { 19 19 20 public ShpMathTransformException() {20 public GeoMathTransformException() { 21 21 super(); 22 22 } 23 23 24 public ShpMathTransformException(String message, Throwable cause) {24 public GeoMathTransformException(String message, Throwable cause) { 25 25 super(message, cause); 26 26 } 27 27 28 public ShpMathTransformException(String message) {28 public GeoMathTransformException(String message) { 29 29 super(message); 30 30 } 31 31 32 public ShpMathTransformException(Throwable cause) {32 public GeoMathTransformException(Throwable cause) { 33 33 super(cause); 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlReader.java
r28000 r28191 44 44 45 45 public class KmlReader extends AbstractReader implements OdConstants { 46 47 public static final String KML_PLACEMARK = "Placemark"; 48 public static final String KML_NAME = "name"; 49 public static final String KML_COLOR = "color"; 50 public static final String KML_SIMPLE_DATA = "SimpleData"; 51 public static final String KML_LINE_STRING = "LineString"; 52 public static final String KML_POINT = "Point"; 53 public static final String KML_POLYGON = "Polygon"; 54 public static final String KML_OUTER_BOUND = "outerBoundaryIs"; 55 public static final String KML_INNER_BOUND = "innerBoundaryIs"; 56 public static final String KML_LINEAR_RING = "LinearRing"; 57 public static final String KML_COORDINATES = "coordinates"; 58 46 59 47 60 private XMLStreamReader parser; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpHandler.java
r28152 r28191 19 19 import java.util.Set; 20 20 21 import org.opengis.referencing.FactoryException;22 import org.opengis.referencing.crs.CoordinateReferenceSystem;23 import org.opengis.referencing.operation.MathTransform;24 21 import org.openstreetmap.josm.data.osm.DataSet; 25 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 23 27 public interface ShpHandler { 28 29 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) throws FactoryException; 30 31 public void setPreferMultipolygonToSimpleWay(boolean prefer); 32 33 public boolean preferMultipolygonToSimpleWay(); 34 35 public void setCheckNodeProximity(boolean check); 36 37 public boolean checkNodeProximity(); 38 39 public void setUseNodeMap(boolean use); 40 41 public boolean useNodeMap(); 24 public interface ShpHandler extends GeographicHandler { 42 25 43 26 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r28158 r28191 19 19 20 20 import java.awt.Component; 21 import java.awt.Image;22 21 import java.io.File; 23 22 import java.io.IOException; 24 23 import java.io.InputStream; 25 import java.util.ArrayList;26 24 import java.util.HashMap; 27 25 import java.util.HashSet; 28 import java.util.List;29 26 import java.util.Map; 30 27 import java.util.Set; 31 32 import javax.swing.Icon;33 import javax.swing.ImageIcon;34 import javax.swing.JOptionPane;35 28 36 29 import org.geotools.data.DataStore; 37 30 import org.geotools.data.FeatureSource; 38 31 import org.geotools.data.shapefile.ShapefileDataStoreFactory; 39 import org.geotools.factory.Hints;40 32 import org.geotools.feature.FeatureCollection; 41 33 import org.geotools.feature.FeatureIterator; 42 import org.geotools.geometry.jts.JTS;43 import org.geotools.referencing.AbstractIdentifiedObject;44 import org.geotools.referencing.CRS;45 import org.geotools.referencing.crs.AbstractCRS;46 import org.geotools.referencing.crs.AbstractDerivedCRS;47 import org.geotools.referencing.crs.AbstractSingleCRS;48 34 import org.opengis.feature.Feature; 49 35 import org.opengis.feature.GeometryAttribute; … … 53 39 import org.opengis.geometry.MismatchedDimensionException; 54 40 import org.opengis.referencing.FactoryException; 55 import org.opengis.referencing.IdentifiedObject;56 import org.opengis.referencing.NoSuchAuthorityCodeException;57 import org.opengis.referencing.crs.CoordinateReferenceSystem;58 import org.opengis.referencing.crs.ProjectedCRS;59 import org.opengis.referencing.cs.CoordinateSystem;60 import org.opengis.referencing.datum.Datum;61 import org.opengis.referencing.operation.MathTransform;62 import org.opengis.referencing.operation.OperationNotFoundException;63 41 import org.opengis.referencing.operation.TransformException; 64 42 import org.openstreetmap.josm.Main; 65 43 import org.openstreetmap.josm.corrector.UserCancelException; 66 import org.openstreetmap.josm.data.coor.LatLon;67 44 import org.openstreetmap.josm.data.osm.DataSet; 68 45 import org.openstreetmap.josm.data.osm.Node; 69 46 import org.openstreetmap.josm.data.osm.OsmPrimitive; 70 47 import org.openstreetmap.josm.data.osm.Relation; 71 import org.openstreetmap.josm.data.osm.RelationMember;72 48 import org.openstreetmap.josm.data.osm.Way; 73 import org.openstreetmap.josm.gui.ExtendedDialog;74 49 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 75 import org.openstreetmap.josm.io.AbstractReader;76 import org.openstreetmap.josm.plugins.opendata.core.OdConstants;77 50 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 78 import org.openstreetmap.josm. tools.ImageProvider;51 import org.openstreetmap.josm.plugins.opendata.core.datasets.NationalHandlers; 79 52 80 53 import com.vividsolutions.jts.geom.Geometry; … … 84 57 import com.vividsolutions.jts.geom.Polygon; 85 58 86 public class ShpReader extends AbstractReader implements OdConstants{59 public class ShpReader extends GeographicReader { 87 60 88 61 private final ShpHandler handler; 89 90 private final CoordinateReferenceSystem wgs84;91 private final Map<String, Node> nodes;92 93 private CoordinateReferenceSystem crs;94 private MathTransform transform;95 96 62 private final Set<OsmPrimitive> featurePrimitives = new HashSet<OsmPrimitive>(); 97 63 98 public ShpReader(ShpHandler handler) throws NoSuchAuthorityCodeException, FactoryException { 64 public ShpReader(ShpHandler handler) { 65 super(handler, NationalHandlers.DEFAULT_SHP_HANDLERS); 99 66 this.handler = handler; 100 this.wgs84 = CRS.decode("EPSG:4326");101 this.nodes = new HashMap<String, Node>();102 67 } 103 68 … … 116 81 } 117 82 118 private static final void compareDebug(CoordinateReferenceSystem crs1, CoordinateReferenceSystem crs2) {119 System.out.println("-- COMPARING "+crs1.getName()+" WITH "+crs2.getName()+" --");120 compareDebug("class", crs1.getClass(), crs2.getClass());121 CoordinateSystem cs1 = crs1.getCoordinateSystem();122 CoordinateSystem cs2 = crs2.getCoordinateSystem();123 if (!compareDebug("cs", cs1, cs2)) {124 Integer dim1 = cs1.getDimension();125 Integer dim2 = cs2.getDimension();126 if (compareDebug("cs.dim", dim1, dim2)) {127 for (int i = 0; i<dim1; i++) {128 compareDebug("cs.axis"+i, cs1.getAxis(i), cs1.getAxis(i));129 }130 }131 }132 if (crs1 instanceof AbstractSingleCRS) {133 Datum datum1 = ((AbstractSingleCRS) crs1).getDatum();134 Datum datum2 = ((AbstractSingleCRS) crs2).getDatum();135 if (!compareDebug("datum", datum1, datum2)) {136 AbstractIdentifiedObject adatum1 = (AbstractIdentifiedObject) datum1;137 AbstractIdentifiedObject adatum2 = (AbstractIdentifiedObject) datum2;138 compareDebug("datum.name1", adatum1.nameMatches(adatum2.getName().getCode()), adatum1.getName(), adatum2.getName());139 compareDebug("datum.name2", adatum2.nameMatches(adatum1.getName().getCode()), adatum2.getName(), adatum1.getName());140 }141 if (crs1 instanceof AbstractDerivedCRS) {142 AbstractDerivedCRS adcrs1 = (AbstractDerivedCRS) crs1;143 AbstractDerivedCRS adcrs2 = (AbstractDerivedCRS) crs2;144 compareDebug("baseCRS", adcrs1.getBaseCRS(), adcrs2.getBaseCRS());145 compareDebug("conversionFromBase", adcrs1.getConversionFromBase(), adcrs2.getConversionFromBase());146 }147 }148 System.out.println("-- COMPARING FINISHED --");149 }150 151 private static final boolean compareDebug(String text, Object o1, Object o2) {152 return compareDebug(text, o1.equals(o2), o1, o2);153 }154 155 private static final boolean compareDebug(String text, IdentifiedObject o1, IdentifiedObject o2) {156 return compareDebug(text, (AbstractIdentifiedObject)o1, (AbstractIdentifiedObject)o2);157 }158 159 private static final boolean compareDebug(String text, AbstractIdentifiedObject o1, AbstractIdentifiedObject o2) {160 return compareDebug(text, o1.equals(o2, false), o1, o2);161 }162 163 private static final boolean compareDebug(String text, boolean result, Object o1, Object o2) {164 System.out.println(text + ": " + result + "("+o1+", "+o2+")");165 return result;166 }167 168 private void findCrsAndMathTransform(CoordinateReferenceSystem coordinateReferenceSystem, Component parent) throws FactoryException, UserCancelException, ShpMathTransformException {169 crs = coordinateReferenceSystem;170 try {171 transform = CRS.findMathTransform(crs, wgs84);172 } catch (OperationNotFoundException e) {173 System.out.println(crs.getName()+": "+e.getMessage()); // Bursa wolf parameters required.174 175 List<CoordinateReferenceSystem> candidates = new ArrayList<CoordinateReferenceSystem>();176 177 // Find matching CRS with Bursa Wolf parameters in EPSG database178 for (String code : CRS.getAuthorityFactory(false).getAuthorityCodes(ProjectedCRS.class)) {179 CoordinateReferenceSystem candidate = CRS.decode(code);180 if (candidate instanceof AbstractCRS && crs instanceof AbstractIdentifiedObject) {181 182 Hints.putSystemDefault(Hints.COMPARISON_TOLERANCE,183 Main.pref.getDouble(PREF_CRS_COMPARISON_TOLERANCE, DEFAULT_CRS_COMPARISON_TOLERANCE));184 if (((AbstractCRS)candidate).equals((AbstractIdentifiedObject)crs, false)) {185 System.out.println("Found a potential CRS: "+candidate.getName());186 candidates.add(candidate);187 } else if (Main.pref.getBoolean(PREF_CRS_COMPARISON_DEBUG, false)) {188 compareDebug(crs, candidate);189 }190 Hints.removeSystemDefault(Hints.COMPARISON_TOLERANCE);191 }192 }193 194 if (candidates.size() > 1) {195 System.err.println("Found several potential CRS.");//TODO: ask user which one to use196 }197 198 if (candidates.size() > 0) {199 CoordinateReferenceSystem newCRS = candidates.get(0);200 try {201 transform = CRS.findMathTransform(newCRS, wgs84, false);202 } catch (OperationNotFoundException ex) {203 System.err.println(newCRS.getName()+": "+e.getMessage());204 }205 }206 207 if (transform == null) {208 if (handler != null) {209 // ask handler if it can provide a math transform210 transform = handler.findMathTransform(crs, wgs84, false);211 }212 if (transform == null) {213 // ask user before trying lenient method214 if (warnLenientMethod(parent, crs)) {215 // User canceled216 throw new UserCancelException();217 }218 System.out.println("Searching for a lenient math transform.");219 transform = CRS.findMathTransform(crs, wgs84, true);220 }221 }222 }223 if (transform == null) {224 throw new ShpMathTransformException("Unable to find math transform !");225 }226 }227 228 83 private void parseFeature(Feature feature, Component parent) 229 throws UserCancelException, ShpMathTransformException, FactoryException,ShpCrsException, MismatchedDimensionException, TransformException {84 throws UserCancelException, GeoMathTransformException, FactoryException, GeoCrsException, MismatchedDimensionException, TransformException { 230 85 featurePrimitives.clear(); 231 86 GeometryAttribute geometry = feature.getDefaultGeometryProperty(); … … 235 90 236 91 if (crs == null && desc != null && desc.getCoordinateReferenceSystem() != null) { 237 findCrsAndMathTransform(desc.getCoordinateReferenceSystem(), parent); 92 crs = desc.getCoordinateReferenceSystem(); 93 findMathTransform(parent, true); 238 94 } else if (crs == null) { 239 throw new ShpCrsException("Unable to detect CRS !");95 throw new GeoCrsException("Unable to detect CRS !"); 240 96 } 241 97 … … 362 218 } 363 219 364 /**365 * returns true if the user wants to cancel, false if they366 * want to continue367 */368 private static final boolean warnLenientMethod(Component parent, CoordinateReferenceSystem crs) {369 ExtendedDialog dlg = new ExtendedDialog(parent,370 tr("Cannot transform to WGS84"),371 new String[] {tr("Cancel"), tr("Continue")});372 dlg.setContent("<html>" +373 tr("JOSM was unable to find a strict mathematical transformation between ''{0}'' and WGS84.<br /><br />"+374 "Do you want to try a <i>lenient</i> method, which will perform a non-precise transformation (<b>with location errors up to 1 km</b>) ?<br/><br/>"+375 "If so, <b>do NOT upload</b> such data to OSM !", crs.getName())+376 "</html>");377 dlg.setButtonIcons(new Icon[] {378 ImageProvider.get("cancel"),379 ImageProvider.overlay(380 ImageProvider.get("ok"),381 new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)),382 ImageProvider.OverlayPosition.SOUTHEAST)});383 dlg.setToolTipTexts(new String[] {384 tr("Cancel"),385 tr("Try lenient method")});386 dlg.setIcon(JOptionPane.WARNING_MESSAGE);387 dlg.setCancelButton(1);388 return dlg.showDialog().getValue() != 2;389 }390 391 220 private static final void readNonGeometricAttributes(Feature feature, OsmPrimitive primitive) { 392 221 for (Property prop : feature.getProperties()) { … … 404 233 } 405 234 } 406 407 private Node getNode(Point p, String key) { 408 Node n = nodes.get(key); 409 if (n == null && handler != null && handler.checkNodeProximity()) { 410 LatLon ll = new LatLon(p.getY(), p.getX()); 411 for (Node node : nodes.values()) { 412 if (node.getCoor().equalsEpsilon(ll)) { 413 return node; 414 } 415 } 416 } 417 return n; 418 } 419 420 private Node createOrGetNode(Point p) throws MismatchedDimensionException, TransformException { 421 Point p2 = (Point) JTS.transform(p, transform); 422 String key = p2.getX()+"/"+p2.getY(); 423 //String key = LatLon.roundToOsmPrecisionStrict(p2.getX())+"/"+LatLon.roundToOsmPrecisionStrict(p2.getY()); 424 Node n = getNode(p2, key); 425 if (n == null) { 426 n = new Node(new LatLon(p2.getY(), p2.getX())); 427 if (handler == null || handler.useNodeMap()) { 428 nodes.put(key, n); 429 } 430 ds.addPrimitive(n); 431 } else if (n.getDataSet() == null) { 432 // ShpHandler may have removed the node from DataSet (see Paris public light handler for example) 433 ds.addPrimitive(n); 434 } 235 236 @Override 237 protected Node createOrGetNode(Point p) throws MismatchedDimensionException, TransformException { 238 Node n = super.createOrGetNode(p); 435 239 featurePrimitives.add(n); 436 240 return n; 437 241 } 438 242 439 private Way createWay(LineString ls) { 440 Way w = new Way(); 441 if (ls != null) { 442 for (int i=0; i<ls.getNumPoints(); i++) { 443 try { 444 w.addNode(createOrGetNode(ls.getPointN(i))); 445 } catch (Exception e) { 446 System.err.println(e.getMessage()); 447 } 448 } 449 } 450 return addOsmPrimitive(w); 451 } 452 453 private Relation createMultipolygon() { 454 Relation r = new Relation(); 455 r.put("type", "multipolygon"); 456 return addOsmPrimitive(r); 457 } 458 459 private void addWayToMp(Relation r, String role, Way w) { 460 //result.addPrimitive(w); 461 r.addMember(new RelationMember(role, w)); 462 } 463 464 private <T extends OsmPrimitive> T addOsmPrimitive(T p) { 465 ds.addPrimitive(p); 243 @Override 244 protected <T extends OsmPrimitive> T addOsmPrimitive(T p) { 466 245 featurePrimitives.add(p); 467 return p;246 return super.addOsmPrimitive(p); 468 247 } 469 248 }
Note:
See TracChangeset
for help on using the changeset viewer.