Search in sources :

Example 21 with Envelope

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 22 with Envelope

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Point(com.vividsolutions.jts.geom.Point) Envelope(com.vividsolutions.jts.geom.Envelope) Point(com.vividsolutions.jts.geom.Point)

Example 23 with Envelope

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;
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) AdminLevel(org.activityinfo.geoadmin.model.AdminLevel) Extents(org.activityinfo.model.type.geo.Extents) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 24 with Envelope

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;
    }
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Example 25 with Envelope

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;
    }
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)111 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Node (org.locationtech.geogig.api.Node)16 Geometry (com.vividsolutions.jts.geom.Geometry)13 ObjectId (org.locationtech.geogig.api.ObjectId)13 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)12 STRtree (com.vividsolutions.jts.index.strtree.STRtree)11 ArrayList (java.util.ArrayList)11 Vertex (org.opentripplanner.routing.graph.Vertex)11 Test (org.junit.Test)9 NodeRef (org.locationtech.geogig.api.NodeRef)9 Edge (org.opentripplanner.routing.graph.Edge)9 LineString (com.vividsolutions.jts.geom.LineString)8 RevTree (org.locationtech.geogig.api.RevTree)8 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 Map (java.util.Map)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 RevFeature (org.locationtech.geogig.api.RevFeature)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5