Changeset 36024 in osm for applications/editors


Ignore:
Timestamp:
2022-10-06T20:35:22+02:00 (21 months ago)
Author:
taylor.smock
Message:

Fix #22179: Add support for GeoPackage in OpenData

This does two things:

  1. Add gt-geopkg to the GeoTools plugin and update the GeoTools version to 27.1
  2. Adds support int OpenData for GeoPackage. This involved a refactor to make it easier to reuse code between the shapefile support and geopackage. As such, it should be much easier to add additional formats supported by GeoTools in the future, if needed.
Location:
applications/editors/josm/plugins
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/geotools/README

    r35903 r36024  
    44    * Licensed under GPL v3 (see LICENSE)
    55
    6 The current embedded version of GeoTools is 26.2.
     6The current embedded version of GeoTools is 27.1.
    77
  • applications/editors/josm/plugins/geotools/ivy.xml

    r35958 r36024  
    1414        <dependency org="org.geotools" name="gt-referencing" rev="${gt.version}" conf="default->default"/>
    1515        <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"/>
    1617        <!-- Dependencies that were not needed in 22.0 (according to lib in svn) -->
    1718        <exclude org="org.geotools" module="gt-imagemosaic"/>
  • applications/editors/josm/plugins/geotools/ivy_settings.xml

    r36008 r36024  
    22<ivysettings>
    33  <!-- 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"/>
    55  <settings defaultResolver="ordered-resolvers"/>
    66  <resolvers>
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java

    r35269 r36024  
    4141import org.openstreetmap.josm.plugins.opendata.core.io.geographic.MifTabImporter;
    4242import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpImporter;
     43import org.openstreetmap.josm.plugins.opendata.core.io.geographic.geopackage.GeoPackageImporter;
    4344import org.openstreetmap.josm.plugins.opendata.core.io.session.OpenDataSessionExporter;
    4445import org.openstreetmap.josm.plugins.opendata.core.io.session.OpenDataSessionImporter;
     
    6768    private OdDialog dialog;
    6869
    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    );
    7685
    7786    public OdPlugin(PluginInformation info) {
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java

    r35275 r36024  
    9292    public static final String JSON_EXT = "json";
    9393    public static final String GEOJSON_EXT = "geojson";
     94    public static final String GEOPACKAGE_EXT = "gpkg";
    9495
    9596    /**
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java

    r33595 r36024  
    2929import org.openstreetmap.josm.plugins.opendata.core.io.geographic.MifHandler;
    3030import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpHandler;
     31import org.openstreetmap.josm.plugins.opendata.core.io.geographic.geopackage.DefaultGeoPackageHandler;
     32import org.openstreetmap.josm.plugins.opendata.core.io.geographic.geopackage.GeoPackageHandler;
    3133import org.openstreetmap.josm.plugins.opendata.core.io.tabular.CsvHandler;
    3234import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler;
     
    8385        setCsvHandler(new DefaultCsvHandler());
    8486        setGmlHandler(new DefaultGmlHandler());
     87        setGeoPackageHandler(new DefaultGeoPackageHandler());
    8588    }
    8689
     
    161164    protected final boolean acceptsCsvXlsFilename(String filename, String ... expected) {
    162165        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);
    163170    }
    164171
     
    480487    }
    481488
     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
    482501    // ------------ Archive handling ------------
    483502
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchShpHandler.java

    r32545 r36024  
    66import org.geotools.referencing.operation.projection.MapProjection.AbstractProvider;
    77import org.opengis.referencing.FactoryException;
    8 import org.opengis.referencing.NoSuchAuthorityCodeException;
    98import org.opengis.referencing.crs.CoordinateReferenceSystem;
    109import org.opengis.referencing.crs.ProjectedCRS;
     
    1211import org.opengis.referencing.operation.MathTransform;
    1312import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultShpHandler;
     13import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GeotoolsHandler;
    1414
     15/**
     16 * A handler for french-specific shapefiles
     17 */
    1518public class FrenchShpHandler extends DefaultShpHandler {
    1619
    1720    @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)) {
    2023            return CRS.decode("EPSG:4471");
    21         } else if (crsName.equalsIgnoreCase("RGFG95_UTM_Zone_22N")) {
     24        } else if ("RGFG95_UTM_Zone_22N".equalsIgnoreCase(crsName)) {
    2225            return CRS.decode("EPSG:2972");
    2326        } else {
     
    2932    public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient)
    3033            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);
    4546                    }
    4647                }
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultShpHandler.java

    r34452 r36024  
    33
    44import java.nio.charset.Charset;
    5 import java.util.ArrayList;
    6 import java.util.List;
    75import java.util.Set;
    86
    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;
    227import org.openstreetmap.josm.data.osm.DataSet;
    238import 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;
    379
    38 public class DefaultShpHandler extends DefaultGeographicHandler implements ShpHandler {
     10/**
     11 * The default shapefile handler
     12 */
     13public class DefaultShpHandler extends DefaultGeographicHandler implements ShpHandler, GeotoolsHandler {
    3914
    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;
    12616
    12717    @Override
    12818    public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives) {
    129         // To be overriden by modules handlers
     19        // To be overridden by modules handlers
    13020    }
    13121
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java

    r35984 r36024  
    7272
    7373/**
    74  * Superclass of geographic format readers (currently GML and SHP).
     74 * Superclass of geographic format readers (currently GML, GPKG, and SHP).
    7575 */
    7676public abstract class GeographicReader extends AbstractReader {
     
    106106    protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
    107107        return null;
     108    }
     109
     110    public GeographicHandler getHandler() {
     111        return this.handler;
    108112    }
    109113
     
    344348    }
    345349
     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     */
    346358    protected void findMathTransform(Component parent, boolean findSimiliarCrs)
    347359            throws FactoryException, UserCancelException, GeoMathTransformException {
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java

    r35125 r36024  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Component;
    7 import java.awt.GraphicsEnvironment;
    86import java.io.BufferedReader;
    97import java.io.File;
     
    1715import java.nio.file.Files;
    1816import java.nio.file.Path;
    19 import java.text.SimpleDateFormat;
    2017import java.util.Arrays;
    21 import java.util.Date;
    2218import java.util.HashMap;
    2319import java.util.HashSet;
     
    2521import java.util.Set;
    2622
    27 import javax.swing.JOptionPane;
    28 
    2923import org.geotools.data.DataStore;
    30 import org.geotools.data.FeatureSource;
    3124import 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;
    3725import 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;
    4426import org.opengis.geometry.MismatchedDimensionException;
    45 import org.opengis.referencing.FactoryException;
    4627import org.opengis.referencing.operation.TransformException;
    4728import org.openstreetmap.josm.data.osm.DataSet;
    4829import org.openstreetmap.josm.data.osm.Node;
    4930import 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;
    5331import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    54 import org.openstreetmap.josm.gui.util.GuiHelper;
    5532import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    5633import org.openstreetmap.josm.plugins.opendata.core.datasets.NationalHandlers;
    5734import org.openstreetmap.josm.tools.Logging;
    58 import org.openstreetmap.josm.tools.UserCancelException;
    5935
    6036/**
     
    8359            throw new IOException(t);
    8460        }
    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_OPTION
    105                                 )) {
    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 of
    123                 // 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 MultiPolygon
    127                 Set<OsmPrimitive> primitives = processGeometryCollection((GeometryCollection) geomObject);
    128                 for (OsmPrimitive prim : primitives) {
    129                     readNonGeometricAttributes(feature, prim);
    130                 }
    131             } else {
    132                 // Debug unknown geometry
    133                 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 ring
    160                     // except if handler prefers it
    161                     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;
    18661    }
    18762
     
    232107                    throw new IOException(tr("Unable to find a data store for file {0}", file.getName()));
    233108                }
    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);
    273110            }
    274111        } catch (IOException e) {
     
    280117        }
    281118        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         }
    305119    }
    306120
Note: See TracChangeset for help on using the changeset viewer.