Changeset 30982 in osm
- Timestamp:
- 2015-02-14T21:48:38+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r30796 r30982 17 17 import java.nio.file.Files; 18 18 import java.nio.file.Path; 19 import java.text.SimpleDateFormat; 20 import java.util.Date; 19 21 import java.util.HashMap; 20 22 import java.util.HashSet; … … 59 61 private final ShpHandler handler; 60 62 private final Set<OsmPrimitive> featurePrimitives = new HashSet<>(); 61 63 62 64 public ShpReader(ShpHandler handler) { 63 65 super(handler, NationalHandlers.DEFAULT_SHP_HANDLERS); … … 78 80 } 79 81 } 80 81 private void parseFeature(Feature feature, final Component parent) 82 83 private void parseFeature(Feature feature, final Component parent) 82 84 throws UserCancelException, GeoMathTransformException, FactoryException, GeoCrsException, MismatchedDimensionException, TransformException { 83 85 featurePrimitives.clear(); … … 86 88 87 89 GeometryDescriptor desc = geometry.getDescriptor(); 88 90 89 91 if (crs == null) { 90 92 if (desc != null && desc.getCoordinateReferenceSystem() != null) { … … 114 116 } 115 117 } 116 118 117 119 OsmPrimitive primitive = null; 118 120 119 121 if (geometry.getValue() instanceof Point) { 120 122 primitive = createOrGetEmptyNode((Point) geometry.getValue()); 121 123 122 124 } else if (geometry.getValue() instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon 123 125 GeometryCollection mp = (GeometryCollection) geometry.getValue(); 124 int nGeometries = mp.getNumGeometries(); 126 int nGeometries = mp.getNumGeometries(); 125 127 if (nGeometries < 1) { 126 128 Main.error("empty geometry collection found"); … … 128 130 Relation r = null; 129 131 Way w = null; 130 132 131 133 for (int i=0; i<nGeometries; i++) { 132 134 Geometry g = mp.getGeometryN(i); … … 166 168 Main.debug("-------------------------------------------------------------"); 167 169 } 168 170 169 171 if (primitive != null) { 170 172 // Read primitive non geometric attributes … … 178 180 transform = null; 179 181 try { 180 if (file != null) { 182 if (file != null) { 181 183 Map<String, Serializable> params = new HashMap<>(); 182 184 Charset charset = null; … … 205 207 throw new IOException(tr("Unable to find a data store for file {0}", file.getName())); 206 208 } 207 209 208 210 String[] typeNames = dataStore.getTypeNames(); 209 211 String typeName = typeNames[0]; 210 212 211 213 FeatureSource<?,?> featureSource = dataStore.getFeatureSource(typeName); 212 214 FeatureCollection<?,?> collection = featureSource.getFeatures(); 213 215 FeatureIterator<?> iterator = collection.features(); 214 216 215 217 if (instance != null) { 216 218 instance.beginTask(tr("Loading shapefile ({0} features)", collection.size()), collection.size()); 217 219 } 218 220 219 221 int n = 0; 220 222 221 223 Component parent = instance != null ? instance.getWindowParent() : Main.parent; 222 224 223 225 try { 224 226 while (iterator.hasNext()) { … … 258 260 return ds; 259 261 } 260 262 261 263 private static final void readNonGeometricAttributes(Feature feature, OsmPrimitive primitive) { 262 try { 263 for (Property prop : feature.getProperties()) { 264 if (!(prop instanceof GeometryAttribute)) { 265 Name name = prop.getName(); 266 Object value = prop.getValue(); 267 if (name != null && value != null) { 268 String sName = name.toString(); 269 String sValue = value.toString(); 270 if (!sName.isEmpty() && !sValue.isEmpty()) { 271 primitive.put(sName, sValue); 272 } 273 } 274 } 275 } 276 } catch (Exception e) { 277 e.printStackTrace(); 278 } 264 try { 265 for (Property prop : feature.getProperties()) { 266 if (!(prop instanceof GeometryAttribute)) { 267 Name name = prop.getName(); 268 Object value = prop.getValue(); 269 if (name != null && value != null) { 270 String sName = name.toString(); 271 String sValue = value.toString(); 272 if (value instanceof Date) { 273 sValue = new SimpleDateFormat("yyyy-MM-dd").format(value); 274 } 275 if (!sName.isEmpty() && !sValue.isEmpty()) { 276 primitive.put(sName, sValue); 277 } 278 } 279 } 280 } 281 } catch (Exception e) { 282 Main.error(e); 283 } 279 284 } 280 285 … … 285 290 return n; 286 291 } 287 292 288 293 @Override 289 294 protected <T extends OsmPrimitive> T addOsmPrimitive(T p) {
Note:
See TracChangeset
for help on using the changeset viewer.