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

Remove duplicated regions for thematic maps #1084

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
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 @@ -153,9 +153,9 @@ protected static SimpleFeatureCollection parseGMLFeatureCollection(InputStream i

protected static List<Region> parse(SimpleFeatureCollection fc, String idProperty, String nameProperty)
throws ServiceException {
final SimpleFeatureIterator it = fc.features();
try {
final List<Region> nameCodes = new ArrayList<>();
final List<String> duplicateIdCheckList = new ArrayList<>();
final List<Region> result = new ArrayList<>();
try (SimpleFeatureIterator it = fc.features()){
while (it.hasNext()) {
final SimpleFeature feature = it.next();
// id might be numeric on source data
Expand All @@ -166,22 +166,26 @@ protected static List<Region> parse(SimpleFeatureCollection fc, String idPropert
") property for region. Properties are:", LOG.getAsString(feature.getProperties()));
continue;
}
if (duplicateIdCheckList.contains(id)) {
LOG.info("Region with id (", id, ") and name(", name,
") has duplicates on the regions listing. Using the first one.");
continue;
}
Region region = new Region(id, name);
try {
region.setPointOnSurface(getPointOnSurface(feature));
region.setGeojson(toGeoJSON((Geometry) feature.getDefaultGeometry(), id, name));
nameCodes.add(region);
result.add(region);
duplicateIdCheckList.add(id);
} catch (Exception ex) {
LOG.warn("Region had invalid geometry:", region, "Error:", ex.getMessage());
}
}
if (nameCodes.isEmpty()) {
if (result.isEmpty()) {
throw new ServiceException("Empty result, check configuration for region id-property=" +
idProperty + " and name-property=" + nameProperty);
}
return nameCodes;
} finally {
it.close();
return result;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public void testGeoJSONResourceFileWorks() throws MismatchedDimensionException,
}
}

@Test
public void testDuplicatedRegions() throws MismatchedDimensionException, FactoryException, TransformException, ServiceException, IOException, JSONException {
String endPoint = "resources://ely4500k.json";
RegionSet elyJson = new RegionSet();
elyJson.setId(-1);
elyJson.setName("oskari:ely4500k");
elyJson.setSrs_name("EPSG:3067");
elyJson.setAttributes(getAttributes("ely", "nimi", endPoint));
List<Region> regions = RegionSetHelper.getRegions(elyJson, "EPSG:3067");
assertEquals(16, regions.size());
}

@Test
public void testFeaturesUrl() throws MismatchedDimensionException, FactoryException, TransformException, ServiceException, IOException, JSONException {
String endPoint = "https://my.domain";
Expand Down
Loading
Loading