use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class ExtractBounds method visit.
@Override
public List<ReferencedEnvelope> visit(Literal literal, @Nullable Object data) {
Object value = literal.getValue();
if (value instanceof Geometry) {
Geometry geom = (Geometry) value;
Envelope literalEnvelope = geom.getEnvelopeInternal();
CoordinateReferenceSystem crs = nativeCrs;
if (geom.getUserData() instanceof CoordinateReferenceSystem) {
crs = (CoordinateReferenceSystem) geom.getUserData();
}
ReferencedEnvelope bbox = new ReferencedEnvelope(literalEnvelope, crs);
bounds.add(bbox);
}
return bounds;
}
use of com.vividsolutions.jts.geom.Envelope in project StreetComplete by westnordost.
the class AddHousenumber method download.
@Override
public boolean download(BoundingBox bbox, final MapDataWithGeometryHandler handler) {
List<ElementWithGeometry> items = downloadBuildingsWithoutAddresses(bbox);
if (items == null)
return false;
// empty result: We are done
if (items.isEmpty())
return true;
List<Geometry> addrAreas = downloadAreasWithAddresses(bbox);
if (addrAreas == null)
return false;
Envelope bounds = null;
for (ElementWithGeometry item : items) {
Envelope addBounds = item.geometry.getEnvelopeInternal();
if (bounds == null)
bounds = addBounds;
else
bounds.expandToInclude(addBounds);
}
// see #885: The area in which the app should search for address nodes (and areas) must be
// adjusted to the bounding box of all the buildings found. The found buildings may in parts
// not be within the specified bounding box. But in exactly that part, there may be an
// address
BoundingBox adjustedBbox = JTSConst.toBoundingBox(bounds);
ArrayList<Point> addrPositions = downloadFreeFloatingPositionsWithAddresses(adjustedBbox);
if (addrPositions == null)
return false;
for (ElementWithGeometry item : items) {
// exclude buildings with housenumber-nodes inside them
int index = indexOfPointIn(item.geometry, addrPositions);
if (index != -1) {
// performance improvement: one housenumber-node cannot be covered by multiple
// buildings. So, it can be removed to reduce the amount of remaining
// point-in-polygon checks
addrPositions.remove(index);
continue;
}
// further exclude buildings that are contained in an area with a housenumber
if (coveredByAnyArea(item.geometry, addrAreas))
continue;
handler.handle(item.element, item.elementGeometry);
}
return true;
}
use of com.vividsolutions.jts.geom.Envelope in project activityinfo by bedatadriven.
the class ImportWindow method buildUpdate.
private AdminLevel buildUpdate() {
int nameAttribute = importForm.getNameAttributeIndex();
int codeAttribute = importForm.getCodeAttributeIndex();
List<AdminEntity> entities = Lists.newArrayList();
Map<ImportKey, AdminEntity> entityMap = Maps.newHashMap();
for (int i = 0; i != tableModel.getRowCount(); ++i) {
if (tableModel.getActionAt(i) == ImportAction.IMPORT) {
ImportFeature feature = tableModel.getFeatureAt(i);
String featureName = feature.getAttributeStringValue(nameAttribute);
AdminEntity parent = tableModel.getParent(i);
if (!validateFeature(feature, featureName, parent)) {
continue;
}
if (Strings.isNullOrEmpty(featureName)) {
throw new RuntimeException("Feature " + i + " has an empty name");
}
// we can't have two entities with the same name within a
// given parent. This happens often because secondary exterior rings
// are stored as separate features.
ImportKey key = new ImportKey(parent, featureName);
if (!entityMap.containsKey(key)) {
AdminEntity entity = new AdminEntity();
String truncatedName = featureName;
if (truncatedName.length() > MAX_NAME_LENGTH) {
truncatedName = truncatedName.substring(0, MAX_NAME_LENGTH);
}
entity.setName(truncatedName);
if (codeAttribute != -1) {
entity.setCode(feature.getAttributeStringValue(codeAttribute));
}
Extents bounds = GeoUtils.toBounds(feature.getEnvelope());
entity.setBounds(bounds);
if (importForm.isGeometryImported()) {
entity.setGeometry(feature.getGeometry());
}
if (parentLevel != null) {
entity.setParentId(parent.getId());
}
entities.add(entity);
entityMap.put(key, entity);
} else {
// add this geometry to the existing entity
LOGGER.info("Merging geometry for entity named '" + featureName + "'");
AdminEntity entity = entityMap.get(key);
Envelope bounds = GeoUtils.toEnvelope(entity.getBounds());
bounds.expandToInclude(feature.getEnvelope());
entity.setBounds(GeoUtils.toBounds(bounds));
if (importForm.isGeometryImported()) {
entity.setGeometry(entity.getGeometry().union(feature.getGeometry()));
}
}
}
}
AdminLevel newLevel = new AdminLevel();
newLevel.setName(importForm.getLevelName());
if (parentLevel != null) {
newLevel.setParentId(parentLevel.getId());
}
newLevel.setEntities(entities);
return newLevel;
}
use of com.vividsolutions.jts.geom.Envelope in project activityinfo by bedatadriven.
the class ParentGuesser method scoreGeography.
/**
* Scores the prospective parent based on geography. A perfectly matched
* parent will entirely contain the child entity. (we only use MBRs here)
*
* @param feature
* @param parent
* the prospective parent to evaluate
* @return a score from 0=poor match, no intersection, 1=perfect match,
* competely contained
*/
public static double scoreGeography(ImportFeature feature, AdminEntity parent) {
Envelope parentEnvelope = GeoUtils.toEnvelope(parent.getBounds());
Envelope childEnvelope = feature.getEnvelope();
if (childEnvelope.getArea() > 0) {
double propContained = parentEnvelope.intersection(childEnvelope).getArea() / childEnvelope.getArea();
return propContained;
} else {
// we have only a point representation
return parentEnvelope.contains(childEnvelope) ? 1 : 0;
}
}
use of com.vividsolutions.jts.geom.Envelope in project activityinfo by bedatadriven.
the class LocationAdminMatcher method scoreGeography.
/**
* Scores the prospective parent based on geography. A perfectly matched
* parent will entirely contain the child entity. (we only use MBRs here)
*
* @param feature
* @param parent
* the prospective parent to evaluate
* @return a score from 0=poor match, no intersection, 1=perfect match,
* competely contained
*/
public double scoreGeography(ImportFeature feature, AdminEntity parent) {
Envelope parentEnvelope = GeoUtils.toEnvelope(parent.getBounds());
Envelope childEnvelope = feature.getEnvelope();
if (childEnvelope.getArea() > 0) {
double propContained = parentEnvelope.intersection(childEnvelope).getArea() / childEnvelope.getArea();
return propContained;
} else {
// we have only a point representation
return parentEnvelope.contains(childEnvelope) ? 1 : 0;
}
}
Aggregations