Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void bulkShpDumper(FeatureSource featureSource, String featureIdField,
- Map<String /* featureIdField */, Map<String /* FieldID */, Object /* Value */>> data)
- throws IOException {
- long t0 = System.currentTimeMillis();
- log.info("Loading shapefile into a memory cache.");
- FeatureCollection<SimpleFeatureType, SimpleFeature> selectedFeatures = featureSource.getFeatures();
- FeatureIterator<SimpleFeature> iterator = selectedFeatures.features();
- List<AttributeDescriptor> descriptors = null;
- while (iterator.hasNext() == true) {
- SimpleFeature feature = iterator.next();
- if (descriptors == null) {
- descriptors = feature.getFeatureType().getAttributeDescriptors();
- }
- Map<String, Object> dataRow = new HashMap<String, Object>();
- for (int idx = 0; idx < descriptors.size(); idx++) {
- AttributeDescriptor desc = descriptors.get(idx);
- Object value = feature.getAttribute(desc.getName());
- dataRow.put(desc.getName().getLocalPart(), value);
- if (((desc.getName().getLocalPart().toLowerCase().contains("geom")) == true) && (value instanceof Point)) {
- //POINT (2.159601897944868 41.36384684287495)
- Point valueAsPoint = (Point) feature.getAttribute(desc.getName());
- dataRow.put("lat", valueAsPoint.getY());
- dataRow.put("lon", valueAsPoint.getX());
- }
- }
- data.put(String.valueOf(dataRow.get(featureIdField)), dataRow);
- }
- long tf = System.currentTimeMillis();
- log.info(MessageFormat.format(
- "All shape features loaded into the cache ({0}).", tf-t0));
- }
Advertisement
Add Comment
Please, Sign In to add comment