Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export shp file #1111

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emanuelaepure10 as discussed I think a null check for value here might have impact on attributes not present in the export. Also, this might not prevent the IndexOutOfBounds exception if all the additional values are not null. I believe we should analyse the data and try to pass in all the attributes during schema creation in step 2.

// 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