Skip to content

Commit

Permalink
fix: export shp file
Browse files Browse the repository at this point in the history
Fix the export of a shape file.

ING-4189
  • Loading branch information
emanuelaepure10 committed Feb 21, 2024
1 parent 5423c78 commit 10e515e
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,16 @@ private Map<String, Map<String, List<SimpleFeature>>> createFeatures(
TypeDefinition type = instance.getDefinition();
String localPart = type.getName().getLocalPart();
if (schemaFtMap.containsKey(localPart)) {
writeGeometryInstanceData(reporter, schemaFbMap, instance, localPart);
List<GeometryProperty<?>> 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<GeometryProperty<?>> geoms = traverseInstanceForGeometries(instance);
for (GeometryProperty<?> geoProp : geoms) {
String key = geoProp.getGeometry().getGeometryType();
SimpleFeature feature = schemaFbMap.get(localPart).get(key)
Expand All @@ -600,15 +600,13 @@ private Map<String, Map<String, List<SimpleFeature>>> 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 <code>QName</code> which tracks multiple
* schemas.
*/
private void writeGeometryInstanceData(IOReporter reporter,
Map<String, Map<String, SimpleFeatureBuilder>> schemaFbMap, Instance instance,
String localPart) {
List<GeometryProperty<?>> geoms = traverseInstanceForGeometries(instance);

Map<String, Map<String, SimpleFeatureBuilder>> schemaFbMap,
List<GeometryProperty<?>> geoms, String localPart) {
for (GeometryProperty<?> geoProp : geoms) {
addGeometryData(reporter, schemaFbMap, localPart, geoProp);
}
Expand All @@ -622,10 +620,11 @@ private void writeGeometryInstanceData(IOReporter reporter,
* @param type type definition.
* @param localPart local part of <code>QName</code> which tracks multiple
* schemas.
* @param geoms from traversing the instance to find geometries
*/
private void writePropertiesInstanceData(
Map<String, Map<String, SimpleFeatureBuilder>> schemaFbMap, Instance instance,
TypeDefinition type, String localPart) {
TypeDefinition type, String localPart, List<GeometryProperty<?>> geoms) {
Collection<? extends PropertyDefinition> allNonComplexProperties = getNonComplexProperties(
type);
for (PropertyDefinition prop : allNonComplexProperties) {
Expand All @@ -635,17 +634,16 @@ private void writePropertiesInstanceData(
&& prop.getName().getLocalPart() != null) {
Object value = new InstanceAccessor(instance)
.findChildren(prop.getName().getLocalPart()).value();
List<GeometryProperty<?>> 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);
}
}
}

}
}
}
Expand Down

0 comments on commit 10e515e

Please sign in to comment.