Changeset 36024 in osm for applications/editors
- Timestamp:
- 2022-10-06T20:35:22+02:00 (2 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geotools/README
r35903 r36024 4 4 * Licensed under GPL v3 (see LICENSE) 5 5 6 The current embedded version of GeoTools is 2 6.2.6 The current embedded version of GeoTools is 27.1. 7 7 -
applications/editors/josm/plugins/geotools/ivy.xml
r35958 r36024 14 14 <dependency org="org.geotools" name="gt-referencing" rev="${gt.version}" conf="default->default"/> 15 15 <dependency org="org.geotools" name="gt-shapefile" rev="${gt.version}" conf="default->default"/> 16 <dependency org="org.geotools" name="gt-geopkg" rev="${gt.version}" conf="default->default"/> 16 17 <!-- Dependencies that were not needed in 22.0 (according to lib in svn) --> 17 18 <exclude org="org.geotools" module="gt-imagemosaic"/> -
applications/editors/josm/plugins/geotools/ivy_settings.xml
r36008 r36024 2 2 <ivysettings> 3 3 <!-- When geotools is updated, run `ant merge-geotools-services` --> 4 <property name="gt.version" value="27. 0"/>4 <property name="gt.version" value="27.1"/> 5 5 <settings defaultResolver="ordered-resolvers"/> 6 6 <resolvers> -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
r35269 r36024 41 41 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.MifTabImporter; 42 42 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpImporter; 43 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.geopackage.GeoPackageImporter; 43 44 import org.openstreetmap.josm.plugins.opendata.core.io.session.OpenDataSessionExporter; 44 45 import org.openstreetmap.josm.plugins.opendata.core.io.session.OpenDataSessionImporter; … … 67 68 private OdDialog dialog; 68 69 69 public final List<AbstractImporter> importers = Arrays.asList(new AbstractImporter[] { 70 new CsvImporter(), new OdsImporter(), new XlsImporter(), // Tabular file formats 71 new KmlKmzImporter(), new ShpImporter(), new MifTabImporter(), new GmlImporter(), // Geographic file formats 72 new ZipImporter(), // Zip archive containing any of the others 73 new SevenZipImporter(), // 7Zip archive containing any of the others 74 xmlImporter // Generic importer for XML files (currently used for Neptune files) 75 }); 70 /** 71 * The importers that will get registered for use by file import 72 */ 73 public final List<AbstractImporter> importers = Arrays.asList( 74 // Tabular file formats 75 new CsvImporter(), new OdsImporter(), new XlsImporter(), 76 // Geographic file formats 77 new KmlKmzImporter(), new ShpImporter(), new MifTabImporter(), new GeoPackageImporter(), new GmlImporter(), 78 // Zip archive containing any of the others 79 new ZipImporter(), 80 // 7Zip archive containing any of the others 81 new SevenZipImporter(), 82 // Generic importer for XML files (currently used for Neptune files) 83 xmlImporter 84 ); 76 85 77 86 public OdPlugin(PluginInformation info) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r35275 r36024 92 92 public static final String JSON_EXT = "json"; 93 93 public static final String GEOJSON_EXT = "geojson"; 94 public static final String GEOPACKAGE_EXT = "gpkg"; 94 95 95 96 /** -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r33595 r36024 29 29 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.MifHandler; 30 30 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpHandler; 31 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.geopackage.DefaultGeoPackageHandler; 32 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.geopackage.GeoPackageHandler; 31 33 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.CsvHandler; 32 34 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler; … … 83 85 setCsvHandler(new DefaultCsvHandler()); 84 86 setGmlHandler(new DefaultGmlHandler()); 87 setGeoPackageHandler(new DefaultGeoPackageHandler()); 85 88 } 86 89 … … 161 164 protected final boolean acceptsCsvXlsFilename(String filename, String ... expected) { 162 165 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.XLS_EXT); 166 } 167 168 protected final boolean acceptsGpkgFilename(String filename, String... expected) { 169 return acceptsFilename(filename, expected, OdConstants.GEOPACKAGE_EXT); 163 170 } 164 171 … … 480 487 } 481 488 489 // ------------ GeoPackage handling ------------ 490 491 private GeoPackageHandler geoPackageHandler; 492 493 public final void setGeoPackageHandler(GeoPackageHandler handler) { 494 this.geoPackageHandler = handler; 495 } 496 497 public final GeoPackageHandler getGeoPackageHandler() { 498 return this.geoPackageHandler; 499 } 500 482 501 // ------------ Archive handling ------------ 483 502 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchShpHandler.java
r32545 r36024 6 6 import org.geotools.referencing.operation.projection.MapProjection.AbstractProvider; 7 7 import org.opengis.referencing.FactoryException; 8 import org.opengis.referencing.NoSuchAuthorityCodeException;9 8 import org.opengis.referencing.crs.CoordinateReferenceSystem; 10 9 import org.opengis.referencing.crs.ProjectedCRS; … … 12 11 import org.opengis.referencing.operation.MathTransform; 13 12 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultShpHandler; 13 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GeotoolsHandler; 14 14 15 /** 16 * A handler for french-specific shapefiles 17 */ 15 18 public class FrenchShpHandler extends DefaultShpHandler { 16 19 17 20 @Override 18 public CoordinateReferenceSystem getCrsFor(String crsName) throws NoSuchAuthorityCodeException,FactoryException {19 if ( crsName.equalsIgnoreCase("RGM04")) {21 public CoordinateReferenceSystem getCrsFor(String crsName) throws FactoryException { 22 if ("RGM04".equalsIgnoreCase(crsName)) { 20 23 return CRS.decode("EPSG:4471"); 21 } else if ( crsName.equalsIgnoreCase("RGFG95_UTM_Zone_22N")) {24 } else if ("RGFG95_UTM_Zone_22N".equalsIgnoreCase(crsName)) { 22 25 return CRS.decode("EPSG:2972"); 23 26 } else { … … 29 32 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 30 33 throws FactoryException { 31 if (sourceCRS.getName().getCode().equalsIgnoreCase("Lambert I Nord")) { 32 if (sourceCRS instanceof ProjectedCRS) { 33 GeodeticDatum datum = ((ProjectedCRS) sourceCRS).getDatum(); 34 if (datum.getPrimeMeridian().getGreenwichLongitude() > 0.0 35 && ((ProjectedCRS) sourceCRS).getConversionFromBase().getMathTransform() instanceof LambertConformal2SP) { 36 LambertConformal2SP lambert = (LambertConformal2SP) ((ProjectedCRS) sourceCRS).getConversionFromBase().getMathTransform(); 37 Double falseNorthing = get(lambert.getParameterValues(), AbstractProvider.FALSE_NORTHING); 38 Double centralmeridian = get(lambert.getParameterValues(), AbstractProvider.CENTRAL_MERIDIAN); 39 if (centralmeridian.equals(0.0)) { 40 if (falseNorthing.equals(200000.0)) { 41 return CRS.findMathTransform(CRS.decode("EPSG:27561"), targetCRS, lenient); 42 } else if (falseNorthing.equals(1200000.0)) { 43 return CRS.findMathTransform(CRS.decode("EPSG:27571"), targetCRS, lenient); 44 } 34 if ("Lambert I Nord".equalsIgnoreCase(sourceCRS.getName().getCode()) && sourceCRS instanceof ProjectedCRS) { 35 GeodeticDatum datum = ((ProjectedCRS) sourceCRS).getDatum(); 36 if (datum.getPrimeMeridian().getGreenwichLongitude() > 0.0 37 && ((ProjectedCRS) sourceCRS).getConversionFromBase().getMathTransform() instanceof LambertConformal2SP) { 38 LambertConformal2SP lambert = (LambertConformal2SP) ((ProjectedCRS) sourceCRS).getConversionFromBase().getMathTransform(); 39 Double falseNorthing = GeotoolsHandler.get(lambert.getParameterValues(), AbstractProvider.FALSE_NORTHING); 40 Double centralmeridian = GeotoolsHandler.get(lambert.getParameterValues(), AbstractProvider.CENTRAL_MERIDIAN); 41 if (centralmeridian.equals(0.0)) { 42 if (falseNorthing.equals(200000.0)) { 43 return CRS.findMathTransform(CRS.decode("EPSG:27561"), targetCRS, lenient); 44 } else if (falseNorthing.equals(1200000.0)) { 45 return CRS.findMathTransform(CRS.decode("EPSG:27571"), targetCRS, lenient); 45 46 } 46 47 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultShpHandler.java
r34452 r36024 3 3 4 4 import java.nio.charset.Charset; 5 import java.util.ArrayList;6 import java.util.List;7 5 import java.util.Set; 8 6 9 import org.geotools.referencing.CRS;10 import org.geotools.referencing.crs.AbstractDerivedCRS;11 import org.geotools.referencing.datum.DefaultEllipsoid;12 import org.geotools.referencing.operation.projection.LambertConformal;13 import org.geotools.referencing.operation.projection.LambertConformal1SP;14 import org.geotools.referencing.operation.projection.LambertConformal2SP;15 import org.geotools.referencing.operation.projection.MapProjection.AbstractProvider;16 import org.opengis.parameter.ParameterDescriptor;17 import org.opengis.parameter.ParameterValueGroup;18 import org.opengis.referencing.FactoryException;19 import org.opengis.referencing.crs.CoordinateReferenceSystem;20 import org.opengis.referencing.datum.GeodeticDatum;21 import org.opengis.referencing.operation.MathTransform;22 7 import org.openstreetmap.josm.data.osm.DataSet; 23 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 import org.openstreetmap.josm.data.projection.AbstractProjection;25 import org.openstreetmap.josm.data.projection.Ellipsoid;26 import org.openstreetmap.josm.data.projection.Projection;27 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;28 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters;29 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters1SP;30 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters2SP;31 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;32 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;33 import org.openstreetmap.josm.plugins.opendata.core.OdConstants;34 import org.openstreetmap.josm.spi.preferences.Config;35 import org.openstreetmap.josm.tools.Logging;36 import org.openstreetmap.josm.tools.Pair;37 9 38 public class DefaultShpHandler extends DefaultGeographicHandler implements ShpHandler { 10 /** 11 * The default shapefile handler 12 */ 13 public class DefaultShpHandler extends DefaultGeographicHandler implements ShpHandler, GeotoolsHandler { 39 14 40 private static final List<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>> 41 ellipsoids = new ArrayList<>(); 42 static { 43 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.GRS80, Ellipsoid.GRS80)); 44 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.WGS84, Ellipsoid.WGS84)); 45 } 46 47 protected static final Double get(ParameterValueGroup values, ParameterDescriptor<?> desc) { 48 return (Double) values.parameter(desc.getName().getCode()).getValue(); 49 } 50 51 private static boolean equals(Double a, Double b) { 52 boolean res = Math.abs(a - b) <= Config.getPref().getDouble( 53 OdConstants.PREF_CRS_COMPARISON_TOLERANCE, OdConstants.DEFAULT_CRS_COMPARISON_TOLERANCE); 54 if (Config.getPref().getBoolean(OdConstants.PREF_CRS_COMPARISON_DEBUG, false)) { 55 Logging.debug("Comparing "+a+" and "+b+" -> "+res); 56 } 57 return res; 58 } 59 60 private Charset dbfCharset = null; 61 62 @Override 63 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 64 throws FactoryException { 65 if (getCrsFor(sourceCRS.getName().getCode()) != null) { 66 return CRS.findMathTransform(getCrsFor(sourceCRS.getName().getCode()), targetCRS, lenient); 67 } else if (sourceCRS instanceof AbstractDerivedCRS && sourceCRS.getName().getCode().equalsIgnoreCase("Lambert_Conformal_Conic")) { 68 List<MathTransform> result = new ArrayList<>(); 69 AbstractDerivedCRS crs = (AbstractDerivedCRS) sourceCRS; 70 MathTransform transform = crs.getConversionFromBase().getMathTransform(); 71 if (transform instanceof LambertConformal && crs.getDatum() instanceof GeodeticDatum) { 72 LambertConformal lambert = (LambertConformal) transform; 73 GeodeticDatum geo = (GeodeticDatum) crs.getDatum(); 74 for (ProjectionChoice choice : ProjectionPreference.getProjectionChoices()) { 75 Projection p = choice.getProjection(); 76 if (p instanceof AbstractProjection) { 77 AbstractProjection ap = (AbstractProjection) p; 78 if (ap.getProj() instanceof LambertConformalConic) { 79 for (Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid> pair : ellipsoids) { 80 if (pair.a.equals(geo.getEllipsoid()) && pair.b.equals(ap.getEllipsoid())) { 81 boolean ok = true; 82 ParameterValueGroup values = lambert.getParameterValues(); 83 Parameters params = ((LambertConformalConic) ap.getProj()).getParameters(); 84 85 ok = ok ? equals(get(values, AbstractProvider.LATITUDE_OF_ORIGIN), params.latitudeOrigin) : ok; 86 ok = ok ? equals(get(values, AbstractProvider.CENTRAL_MERIDIAN), ap.getCentralMeridian()) : ok; 87 ok = ok ? equals(get(values, AbstractProvider.SCALE_FACTOR), ap.getScaleFactor()) : ok; 88 ok = ok ? equals(get(values, AbstractProvider.FALSE_EASTING), ap.getFalseEasting()) : ok; 89 ok = ok ? equals(get(values, AbstractProvider.FALSE_NORTHING), ap.getFalseNorthing()) : ok; 90 91 if (lambert instanceof LambertConformal2SP && params instanceof Parameters2SP) { 92 Parameters2SP param = (Parameters2SP) params; 93 ok = ok ? equals(Math.min(get(values, AbstractProvider.STANDARD_PARALLEL_1), 94 get(values, AbstractProvider.STANDARD_PARALLEL_2)), 95 Math.min(param.standardParallel1, param.standardParallel2)) : ok; 96 ok = ok ? equals(Math.max(get(values, AbstractProvider.STANDARD_PARALLEL_1), 97 get(values, AbstractProvider.STANDARD_PARALLEL_2)), 98 Math.max(param.standardParallel1, param.standardParallel2)) : ok; 99 100 } else if (!(lambert instanceof LambertConformal1SP && params instanceof Parameters1SP)) { 101 ok = false; 102 } 103 104 if (ok) { 105 try { 106 result.add(CRS.findMathTransform(CRS.decode(p.toCode()), targetCRS, lenient)); 107 } catch (FactoryException e) { 108 Logging.error(e.getMessage()); 109 } 110 } 111 } 112 } 113 } 114 } 115 } 116 } 117 if (!result.isEmpty()) { 118 if (result.size() > 1) { 119 Logging.warn("Found multiple projections !"); // TODO: something 120 } 121 return result.get(0); 122 } 123 } 124 return null; 125 } 15 private Charset dbfCharset; 126 16 127 17 @Override 128 18 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives) { 129 // To be overrid en by modules handlers19 // To be overridden by modules handlers 130 20 } 131 21 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java
r35984 r36024 72 72 73 73 /** 74 * Superclass of geographic format readers (currently GML and SHP).74 * Superclass of geographic format readers (currently GML, GPKG, and SHP). 75 75 */ 76 76 public abstract class GeographicReader extends AbstractReader { … … 106 106 protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 107 107 return null; 108 } 109 110 public GeographicHandler getHandler() { 111 return this.handler; 108 112 } 109 113 … … 344 348 } 345 349 350 /** 351 * Find the math transform for the CRS used by this reader 352 * @param parent The parent component, used for showing dialogs 353 * @param findSimiliarCrs {@code true} if we don't need to find the exact CRS 354 * @throws FactoryException See {@link CRS#findMathTransform}, {@link org.opengis.referencing.AuthorityFactory#getAuthorityCodes} 355 * @throws UserCancelException If the user cancelled in one of the message dialogs 356 * @throws GeoMathTransformException If no transform could be found 357 */ 346 358 protected void findMathTransform(Component parent, boolean findSimiliarCrs) 347 359 throws FactoryException, UserCancelException, GeoMathTransformException { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r35125 r36024 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component;7 import java.awt.GraphicsEnvironment;8 6 import java.io.BufferedReader; 9 7 import java.io.File; … … 17 15 import java.nio.file.Files; 18 16 import java.nio.file.Path; 19 import java.text.SimpleDateFormat;20 17 import java.util.Arrays; 21 import java.util.Date;22 18 import java.util.HashMap; 23 19 import java.util.HashSet; … … 25 21 import java.util.Set; 26 22 27 import javax.swing.JOptionPane;28 29 23 import org.geotools.data.DataStore; 30 import org.geotools.data.FeatureSource;31 24 import org.geotools.data.shapefile.ShapefileDataStoreFactory; 32 import org.geotools.feature.FeatureCollection;33 import org.geotools.feature.FeatureIterator;34 import org.locationtech.jts.geom.Geometry;35 import org.locationtech.jts.geom.GeometryCollection;36 import org.locationtech.jts.geom.LineString;37 25 import org.locationtech.jts.geom.Point; 38 import org.locationtech.jts.geom.Polygon;39 import org.opengis.feature.Feature;40 import org.opengis.feature.GeometryAttribute;41 import org.opengis.feature.Property;42 import org.opengis.feature.type.GeometryDescriptor;43 import org.opengis.feature.type.Name;44 26 import org.opengis.geometry.MismatchedDimensionException; 45 import org.opengis.referencing.FactoryException;46 27 import org.opengis.referencing.operation.TransformException; 47 28 import org.openstreetmap.josm.data.osm.DataSet; 48 29 import org.openstreetmap.josm.data.osm.Node; 49 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 50 import org.openstreetmap.josm.data.osm.Relation;51 import org.openstreetmap.josm.data.osm.Way;52 import org.openstreetmap.josm.gui.MainApplication;53 31 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 54 import org.openstreetmap.josm.gui.util.GuiHelper;55 32 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 56 33 import org.openstreetmap.josm.plugins.opendata.core.datasets.NationalHandlers; 57 34 import org.openstreetmap.josm.tools.Logging; 58 import org.openstreetmap.josm.tools.UserCancelException;59 35 60 36 /** … … 83 59 throw new IOException(t); 84 60 } 85 }86 87 private void parseFeature(Feature feature, final Component parent) throws UserCancelException, GeoMathTransformException,88 FactoryException, GeoCrsException, MismatchedDimensionException, TransformException {89 featurePrimitives.clear();90 GeometryAttribute geometry = feature.getDefaultGeometryProperty();91 if (geometry != null) {92 93 GeometryDescriptor desc = geometry.getDescriptor();94 95 if (crs == null) {96 if (desc != null && desc.getCoordinateReferenceSystem() != null) {97 crs = desc.getCoordinateReferenceSystem();98 } else if (!GraphicsEnvironment.isHeadless()) {99 GuiHelper.runInEDTAndWait(() -> {100 if (0 == JOptionPane.showConfirmDialog(101 parent,102 tr("Unable to detect Coordinate Reference System.\nWould you like to fallback to ESPG:4326 (WGS 84) ?"),103 tr("Warning: CRS not found"),104 JOptionPane.YES_NO_CANCEL_OPTION105 )) {106 crs = wgs84;107 }108 });109 } else {110 // Always use WGS84 in headless mode (used for unit tests only)111 crs = wgs84;112 }113 if (crs != null) {114 findMathTransform(parent, true);115 } else {116 throw new GeoCrsException(tr("Unable to detect CRS !"));117 }118 }119 120 Object geomObject = geometry.getValue();121 if (geomObject instanceof Point) { // TODO: Support LineString and Polygon.122 // Sure you could have a Set of 1 object and join these 2 branches of123 // code, but I feel there would be a performance hit.124 OsmPrimitive primitive = createOrGetEmptyNode((Point) geomObject);125 readNonGeometricAttributes(feature, primitive);126 } else if (geomObject instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon127 Set<OsmPrimitive> primitives = processGeometryCollection((GeometryCollection) geomObject);128 for (OsmPrimitive prim : primitives) {129 readNonGeometricAttributes(feature, prim);130 }131 } else {132 // Debug unknown geometry133 Logging.debug("\ttype: "+geometry.getType());134 Logging.debug("\tbounds: "+geometry.getBounds());135 Logging.debug("\tdescriptor: "+desc);136 Logging.debug("\tname: "+geometry.getName());137 Logging.debug("\tvalue: "+geomObject);138 Logging.debug("\tid: "+geometry.getIdentifier());139 Logging.debug("-------------------------------------------------------------");140 }141 }142 }143 144 protected Set<OsmPrimitive> processGeometryCollection(GeometryCollection gc) throws TransformException {145 // A feture may be a collection. This set holds the items of the collection.146 Set<OsmPrimitive> primitives = new HashSet<>();147 int nGeometries = gc.getNumGeometries();148 if (nGeometries < 1) {149 Logging.error("empty geometry collection found");150 } else {151 // Create the primitive "op" and add it to the set of primitives.152 for (int i = 0; i < nGeometries; i++) {153 OsmPrimitive op = null;154 Geometry g = gc.getGeometryN(i);155 if (g instanceof Polygon) {156 // TODO: Split this section between Polygon and MultiPolygon.157 Relation r = (Relation) op;158 Polygon p = (Polygon) g;159 // Do not create relation if there's only one polygon without interior ring160 // except if handler prefers it161 if (r == null && (nGeometries > 1 || p.getNumInteriorRing() > 0 ||162 (handler != null && handler.preferMultipolygonToSimpleWay()))) {163 r = createMultipolygon();164 }165 Way w = createOrGetWay(p.getExteriorRing());166 if (r != null) {167 addWayToMp(r, "outer", w);168 for (int j = 0; j < p.getNumInteriorRing(); j++) {169 addWayToMp(r, "inner", createOrGetWay(p.getInteriorRingN(j)));170 }171 }172 op = r != null ? r : w;173 } else if (g instanceof LineString) {174 op = createOrGetWay((LineString) g);175 } else if (g instanceof Point) {176 op = createOrGetNode((Point) g);177 } else {178 Logging.error("unsupported geometry : "+g);179 }180 if (op != null) {181 primitives.add(op);182 }183 }184 }185 return primitives;186 61 } 187 62 … … 232 107 throw new IOException(tr("Unable to find a data store for file {0}", file.getName())); 233 108 } 234 235 String[] typeNames = dataStore.getTypeNames(); 236 String typeName = typeNames[0]; 237 238 FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName); 239 FeatureCollection<?, ?> collection = featureSource.getFeatures(); 240 241 if (instance != null) { 242 instance.beginTask(tr("Loading shapefile ({0} features)", collection.size()), collection.size()); 243 } 244 245 int n = 0; 246 247 Component parent = instance != null ? instance.getWindowParent() : MainApplication.getMainFrame(); 248 249 try (FeatureIterator<?> iterator = collection.features()) { 250 while (iterator.hasNext()) { 251 n++; 252 try { 253 Feature feature = iterator.next(); 254 parseFeature(feature, parent); 255 if (handler != null) { 256 handler.notifyFeatureParsed(feature, ds, featurePrimitives); 257 } 258 } catch (UserCancelException e) { 259 e.printStackTrace(); 260 return ds; 261 } 262 if (instance != null) { 263 instance.worked(1); 264 instance.setCustomText(n+"/"+collection.size()); 265 } 266 } 267 } finally { 268 nodes.clear(); 269 if (instance != null) { 270 instance.setCustomText(null); 271 } 272 } 109 new GeotoolsConverter(this, dataStore).convert(instance); 273 110 } 274 111 } catch (IOException e) { … … 280 117 } 281 118 return ds; 282 }283 284 private static void readNonGeometricAttributes(Feature feature, OsmPrimitive primitive) {285 try {286 for (Property prop : feature.getProperties()) {287 if (!(prop instanceof GeometryAttribute)) {288 Name name = prop.getName();289 Object value = prop.getValue();290 if (name != null && value != null) {291 String sName = name.toString();292 String sValue = value.toString();293 if (value instanceof Date) {294 sValue = new SimpleDateFormat("yyyy-MM-dd").format(value);295 }296 if (!sName.isEmpty() && !sValue.isEmpty()) {297 primitive.put(sName, sValue);298 }299 }300 }301 }302 } catch (Exception e) {303 Logging.error(e);304 }305 119 } 306 120
Note:
See TracChangeset
for help on using the changeset viewer.