Merge "Issue #2720 Improve efficiency of merging polygons in edit area generation" into omaha_14.2.1
Former-commit-id:d218961e3f
[formerly333b755999
] [formerly99d6ce0e8f
[formerly 9ecd7ba5d65753a8a67d31d0d690d4ff5474eac6]] Former-commit-id:99d6ce0e8f
Former-commit-id:173d8c7219
This commit is contained in:
commit
23fd8a24ce
1 changed files with 38 additions and 17 deletions
|
@ -37,6 +37,7 @@ import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import jep.JepException;
|
import jep.JepException;
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
|
||||||
* from localMaps.py could not be found,
|
* from localMaps.py could not be found,
|
||||||
* warnings clean up.
|
* warnings clean up.
|
||||||
* Sep 30, 2013 #2361 njensen Use JAXBManager for XML
|
* Sep 30, 2013 #2361 njensen Use JAXBManager for XML
|
||||||
|
* Jan 21, 2014 #2720 randerso Improve efficiency of merging polygons in edit area generation
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -436,7 +438,7 @@ public class MapManager {
|
||||||
List<Coordinate> values = new ArrayList<Coordinate>();
|
List<Coordinate> values = new ArrayList<Coordinate>();
|
||||||
for (int j = 0; j < iscMarkersID.size(); j++) {
|
for (int j = 0; j < iscMarkersID.size(); j++) {
|
||||||
int index = _config.allSites().indexOf(iscMarkersID.get(j));
|
int index = _config.allSites().indexOf(iscMarkersID.get(j));
|
||||||
if (index != -1
|
if ((index != -1)
|
||||||
&& _config.officeTypes().get(index)
|
&& _config.officeTypes().get(index)
|
||||||
.equals(foundOfficeTypes.get(i))) {
|
.equals(foundOfficeTypes.get(i))) {
|
||||||
values.add(iscMarkers.get(j));
|
values.add(iscMarkers.get(j));
|
||||||
|
@ -512,7 +514,7 @@ public class MapManager {
|
||||||
String thisSite = _config.getSiteID().get(0);
|
String thisSite = _config.getSiteID().get(0);
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
String n = data.get(i).getId().getName();
|
String n = data.get(i).getId().getName();
|
||||||
if (n.length() == 7 && n.startsWith("ISC_")) {
|
if ((n.length() == 7) && n.startsWith("ISC_")) {
|
||||||
String cwa = n.substring(4, 7);
|
String cwa = n.substring(4, 7);
|
||||||
if (cwa.equals(thisSite)) {
|
if (cwa.equals(thisSite)) {
|
||||||
statusHandler
|
statusHandler
|
||||||
|
@ -597,8 +599,8 @@ public class MapManager {
|
||||||
} else {
|
} else {
|
||||||
// Write the new edit area file.
|
// Write the new edit area file.
|
||||||
try {
|
try {
|
||||||
ReferenceData.getJAXBManager().marshalToXmlFile(
|
ReferenceData.getJAXBManager().marshalToXmlFile(ref,
|
||||||
ref, path.getAbsolutePath());
|
path.getAbsolutePath());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
statusHandler.error("Error writing edit area to file "
|
statusHandler.error("Error writing edit area to file "
|
||||||
+ path.getAbsolutePath(), e);
|
+ path.getAbsolutePath(), e);
|
||||||
|
@ -827,7 +829,7 @@ public class MapManager {
|
||||||
PreparedGeometry boundingGeometry = PreparedGeometryFactory
|
PreparedGeometry boundingGeometry = PreparedGeometryFactory
|
||||||
.prepare(p);
|
.prepare(p);
|
||||||
|
|
||||||
Map<String, ReferenceData> tempData = new HashMap<String, ReferenceData>();
|
Map<String, Geometry> tempData = new HashMap<String, Geometry>();
|
||||||
while (shapeSource.hasNext()) {
|
while (shapeSource.hasNext()) {
|
||||||
SimpleFeature f = shapeSource.next();
|
SimpleFeature f = shapeSource.next();
|
||||||
Map<String, Object> info = shapeSource.getAttributes(f);
|
Map<String, Object> info = shapeSource.getAttributes(f);
|
||||||
|
@ -838,7 +840,7 @@ public class MapManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
String editAreaName = runNamer(mapDef.getInstanceName(), info);
|
String editAreaName = runNamer(mapDef.getInstanceName(), info);
|
||||||
ReferenceData tmp;
|
Geometry tmp;
|
||||||
|
|
||||||
// validate edit area name, add edit area to the dictionary
|
// validate edit area name, add edit area to the dictionary
|
||||||
String ean = validateEAN(editAreaName);
|
String ean = validateEAN(editAreaName);
|
||||||
|
@ -859,14 +861,25 @@ public class MapManager {
|
||||||
// handle append case
|
// handle append case
|
||||||
tmp = tempData.get(ean);
|
tmp = tempData.get(ean);
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
mp = mp.union(tmp.getPolygons(CoordinateType.LATLON));
|
// Combine multiple geometries into a geometry collection
|
||||||
mp = mp.buffer(0.0);
|
mp = gf.buildGeometry(Arrays.asList(mp, tmp));
|
||||||
}
|
}
|
||||||
// handle new case
|
// handle new case
|
||||||
else {
|
else {
|
||||||
created.add(ean);
|
created.add(ean);
|
||||||
editAreaAttrs.put(ean, info);
|
editAreaAttrs.put(ean, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempData.put(ean, mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Entry<String, Geometry> entry : tempData.entrySet()) {
|
||||||
|
String ean = entry.getKey();
|
||||||
|
Geometry mp = entry.getValue();
|
||||||
|
|
||||||
|
// Compute buffer(0.0) to clean up geometry issues
|
||||||
|
mp = mp.buffer(0.0);
|
||||||
|
|
||||||
MultiPolygon polygons;
|
MultiPolygon polygons;
|
||||||
if (mp instanceof MultiPolygon) {
|
if (mp instanceof MultiPolygon) {
|
||||||
polygons = (MultiPolygon) mp;
|
polygons = (MultiPolygon) mp;
|
||||||
|
@ -874,13 +887,21 @@ public class MapManager {
|
||||||
polygons = gf
|
polygons = gf
|
||||||
.createMultiPolygon(new Polygon[] { (Polygon) mp });
|
.createMultiPolygon(new Polygon[] { (Polygon) mp });
|
||||||
} else {
|
} else {
|
||||||
statusHandler.info("Creating empty polygon");
|
String error = "Table: " + shapeSource.getTableName()
|
||||||
|
+ " edit area:" + ean
|
||||||
|
+ " contains geometry of type "
|
||||||
|
+ mp.getClass().getSimpleName()
|
||||||
|
+ " Creating empty polygon";
|
||||||
|
statusHandler.error(error);
|
||||||
polygons = gf.createMultiPolygon(new Polygon[] {});
|
polygons = gf.createMultiPolygon(new Polygon[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!polygons.isValid()) {
|
if (!polygons.isValid()) {
|
||||||
String error = shapeSource.getTableName()
|
String error = "Table: "
|
||||||
+ " contains invalid polygons.";
|
+ shapeSource.getTableName()
|
||||||
|
+ " edit area:"
|
||||||
|
+ ean
|
||||||
|
+ " contains invalid polygons. This edit area will be skipped.";
|
||||||
for (int i = 0; i < polygons.getNumGeometries(); i++) {
|
for (int i = 0; i < polygons.getNumGeometries(); i++) {
|
||||||
Geometry g = polygons.getGeometryN(i);
|
Geometry g = polygons.getGeometryN(i);
|
||||||
if (!g.isValid()) {
|
if (!g.isValid()) {
|
||||||
|
@ -888,14 +909,14 @@ public class MapManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statusHandler.error(error);
|
statusHandler.error(error);
|
||||||
}
|
continue;
|
||||||
|
|
||||||
tempData.put(ean, new ReferenceData(_config.dbDomain(),
|
|
||||||
new ReferenceID(ean), polygons, CoordinateType.LATLON));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// transfer dictionary values to Seq values
|
// transfer dictionary values to Seq values
|
||||||
data.addAll(tempData.values());
|
data.add(new ReferenceData(_config.dbDomain(), new ReferenceID(
|
||||||
|
ean), polygons, CoordinateType.LATLON));
|
||||||
|
}
|
||||||
|
|
||||||
tempData.clear();
|
tempData.clear();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String error = "********* EDIT AREA GENERATION ERROR - Create Reference Data *********\n"
|
String error = "********* EDIT AREA GENERATION ERROR - Create Reference Data *********\n"
|
||||||
|
@ -954,13 +975,13 @@ public class MapManager {
|
||||||
|
|
||||||
// strip out white space and punctuation (except _)
|
// strip out white space and punctuation (except _)
|
||||||
for (int i = s.length() - 1; i >= 0; i--) {
|
for (int i = s.length() - 1; i >= 0; i--) {
|
||||||
if (!Character.isLetterOrDigit(s.charAt(i)) && s.charAt(i) != '_') {
|
if (!Character.isLetterOrDigit(s.charAt(i)) && (s.charAt(i) != '_')) {
|
||||||
s = s.substring(0, i) + s.substring(i + 1);
|
s = s.substring(0, i) + s.substring(i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure 1st character is not a number. If a number, preprend.
|
// ensure 1st character is not a number. If a number, preprend.
|
||||||
if (s.length() > 0 && Character.isDigit(s.charAt(0))) {
|
if ((s.length() > 0) && Character.isDigit(s.charAt(0))) {
|
||||||
s = "ea" + s;
|
s = "ea" + s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue