From 295b87579bfe361df03c3f71df7afc13ae422129 Mon Sep 17 00:00:00 2001 From: Emanuela Epure <67077116+emanuelaepure10@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:24:15 +0100 Subject: [PATCH] fix: export shp file Fix the export of a shape file. ING-4189 --- .../shp/writer/ShapefileInstanceWriter.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/writer/ShapefileInstanceWriter.java b/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/writer/ShapefileInstanceWriter.java index 4193764f19..08d476caa9 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/writer/ShapefileInstanceWriter.java +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/writer/ShapefileInstanceWriter.java @@ -569,16 +569,16 @@ private Map>> createFeatures( TypeDefinition type = instance.getDefinition(); String localPart = type.getName().getLocalPart(); if (schemaFtMap.containsKey(localPart)) { - writeGeometryInstanceData(reporter, schemaFbMap, instance, localPart); + List> geoms = traverseInstanceForGeometries(instance); + writeGeometryInstanceData(reporter, schemaFbMap, geoms, localPart); // add data for the rest of the properties. - writePropertiesInstanceData(schemaFbMap, instance, type, localPart); + writePropertiesInstanceData(schemaFbMap, instance, type, localPart, geoms); // create list of simple features. // fix in case geometries have multiple geometry types but // single geometry in data. So, always extract geometries // from instance and update to schema. Otherwise the data // will be updated to all the geometries - List> geoms = traverseInstanceForGeometries(instance); for (GeometryProperty geoProp : geoms) { String key = geoProp.getGeometry().getGeometryType(); SimpleFeature feature = schemaFbMap.get(localPart).get(key) @@ -600,15 +600,13 @@ private Map>> createFeatures( * * @param reporter reporter. * @param schemaFbMap map of feature builder to write the data to. - * @param instance instance + * @param geoms from traversing the instance to find geometries * @param localPart local part of QName which tracks multiple * schemas. */ private void writeGeometryInstanceData(IOReporter reporter, - Map> schemaFbMap, Instance instance, - String localPart) { - List> geoms = traverseInstanceForGeometries(instance); - + Map> schemaFbMap, + List> geoms, String localPart) { for (GeometryProperty geoProp : geoms) { addGeometryData(reporter, schemaFbMap, localPart, geoProp); } @@ -622,10 +620,11 @@ private void writeGeometryInstanceData(IOReporter reporter, * @param type type definition. * @param localPart local part of QName which tracks multiple * schemas. + * @param geoms from traversing the instance to find geometries */ private void writePropertiesInstanceData( Map> schemaFbMap, Instance instance, - TypeDefinition type, String localPart) { + TypeDefinition type, String localPart, List> geoms) { Collection allNonComplexProperties = getNonComplexProperties( type); for (PropertyDefinition prop : allNonComplexProperties) { @@ -635,17 +634,16 @@ private void writePropertiesInstanceData( && prop.getName().getLocalPart() != null) { Object value = new InstanceAccessor(instance) .findChildren(prop.getName().getLocalPart()).value(); - List> geoms = traverseInstanceForGeometries(instance); - // add value by traversing geometryType from instance - for (GeometryProperty geoProp : geoms) { - if (geoProp.getGeometry() != null) { - String geometryType = geoProp.getGeometry().getGeometryType(); - if (schemaFbMap.get(localPart) != null - && schemaFbMap.get(localPart).get(geometryType) != null) { - schemaFbMap.get(localPart).get(geometryType).add(value); + if (schemaFbMap.get(localPart) != null && value != null) { + // add value by traversing geometryType from instance + for (GeometryProperty geoProp : geoms) { + if (geoProp.getGeometry() != null) { + String geometryType = geoProp.getGeometry().getGeometryType(); + if (schemaFbMap.get(localPart).get(geometryType) != null) { + schemaFbMap.get(localPart).get(geometryType).add(value); + } } } - } } }