Search in sources :

Example 41 with Point

use of com.vividsolutions.jts.geom.Point in project ddf by codice.

the class TestPubSubOgcFilter method convertMetacardToFeature.

private Feature convertMetacardToFeature(MetacardImpl metacard) {
    // other available FeatureType's ComplexFeatureTypeImpl (link features),
    // FeatureTypeImpl, NonFeatureTypeProxy, SimpleFeatureTypeImpl,
    // UniqueNameFeatureTypeImpl
    final FeatureType pubSubFeature = generateMetacardFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) pubSubFeature);
    featureBuilder.set(Metacard.TITLE, "Muppet Metacard");
    featureBuilder.set(Metacard.CONTENT_TYPE, "Talking Green Frog");
    featureBuilder.set(Metacard.CREATED, new Date());
    featureBuilder.set(Metacard.MODIFIED, new Date());
    featureBuilder.set(Metacard.EXPIRATION, new Date());
    featureBuilder.set(Metacard.EFFECTIVE, new Date());
    featureBuilder.set(Metacard.METADATA, null);
    com.vividsolutions.jts.geom.GeometryFactory geoFactory = JTSFactoryFinder.getGeometryFactory(null);
    com.vividsolutions.jts.geom.Point point = geoFactory.createPoint(new Coordinate(-112, 28));
    featureBuilder.set(Metacard.GEOGRAPHY, point);
    return featureBuilder.buildFeature("KTF1");
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) Date(java.util.Date) Point(com.vividsolutions.jts.geom.Point) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 42 with Point

use of com.vividsolutions.jts.geom.Point in project ddf by codice.

the class TestPubSubOgcFilter method generateSampleFeature.

private SimpleFeature generateSampleFeature() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("PubSubFeature");
    // add properties
    b.add("name", String.class);
    b.add("classification", Integer.class);
    b.add("height", Double.class);
    com.vividsolutions.jts.geom.GeometryFactory geoFactory = JTSFactoryFinder.getGeometryFactory(null);
    // add geo
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("geo", Point.class);
    final SimpleFeatureType pubSubFeature = b.buildFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(pubSubFeature);
    featureBuilder.set("name", "FirstFeature");
    featureBuilder.set("classification", 10);
    featureBuilder.set("height", 5.8);
    com.vividsolutions.jts.geom.Point point = geoFactory.createPoint(new Coordinate(-112, 28));
    featureBuilder.set("geo", point);
    SimpleFeature feature = featureBuilder.buildFeature("f1");
    // it looks like if I add an attribute into the feature that is of geometry type, it
    // automatically
    // becomes the default geo property. If no geo is specified, getDefaultGeometryProperty
    // returns null
    GeometryAttribute defaultGeo = feature.getDefaultGeometryProperty();
    LOGGER.debug("geo name: {}", defaultGeo.getName());
    LOGGER.debug("geo: {}", defaultGeo);
    return feature;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryAttribute(org.opengis.feature.GeometryAttribute) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 43 with Point

use of com.vividsolutions.jts.geom.Point in project GeoGig by boundlessgeo.

the class ChangesetContentsScanner method parsePrimitive.

Primitive parsePrimitive(XMLStreamReader reader) throws XMLStreamException {
    reader.require(START_ELEMENT, null, null);
    final String primitiveName = reader.getLocalName();
    checkArgument(PRIMITIVE_TAGS.contains(primitiveName));
    Primitive primitive = inferrPrimitive(reader);
    primitive.setId(Long.valueOf(reader.getAttributeValue(null, "id")));
    primitive.setVisible(Boolean.valueOf(reader.getAttributeValue(null, "visible")));
    primitive.setTimestamp(parseDateTime(reader.getAttributeValue(null, "timestamp")));
    primitive.setUserName(reader.getAttributeValue(null, "user"));
    Long uid = Long.valueOf(fromNullable(reader.getAttributeValue(null, "uid")).or("-1"));
    primitive.setUserId(uid);
    Integer version = Integer.valueOf(fromNullable(reader.getAttributeValue(null, "version")).or("1"));
    primitive.setVersion(version);
    primitive.setChangesetId(Long.valueOf(reader.getAttributeValue(null, "changeset")));
    if (primitive instanceof Node) {
        Node node = (Node) primitive;
        String lat = reader.getAttributeValue(null, "lat");
        String lon = reader.getAttributeValue(null, "lon");
        // may be null in case of a delete change
        if (lat != null && lon != null) {
            double x = Double.valueOf(lon);
            double y = Double.valueOf(lat);
            Point location = GEOMFACT.createPoint(new Coordinate(x, y));
            node.setLocation(location);
        }
        parseNodeContents(node, reader);
    } else if (primitive instanceof Way) {
        Way way = (Way) primitive;
        parseWayContents(way, reader);
    } else {
        Relation relation = (Relation) primitive;
        parseRelationContents(relation, reader);
    }
    reader.require(END_ELEMENT, null, primitiveName);
    return primitive;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point)

Example 44 with Point

use of com.vividsolutions.jts.geom.Point in project GeoGig by boundlessgeo.

the class GeometrySerializer method read.

@Override
public Geometry read(DataInput in) throws IOException {
    final int typeAndMasks = readUnsignedVarInt(in);
    Geometry geom;
    if ((typeAndMasks & POINT) == POINT) {
        geom = GEOMFAC.createPoint(EncodingSequenceFilter.readCoordinate(in));
    } else if ((typeAndMasks & LINESTRING) == LINESTRING) {
        CoordinateSequence cs = EncodingSequenceFilter.read(in);
        geom = GEOMFAC.createLineString(cs);
    } else {
        throw new UnsupportedOperationException();
    }
    return geom;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 45 with Point

use of com.vividsolutions.jts.geom.Point in project GeoGig by boundlessgeo.

the class OSMHistoryImport method insertChanges.

/**
     * @param cli
     * @param changes
     * @param featureFilter
     * @throws IOException
     */
private long insertChanges(GeogigCLI cli, final Iterator<Change> changes, @Nullable Envelope featureFilter) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    final Repository repository = geogig.getRepository();
    final WorkingTree workTree = repository.workingTree();
    Map<Long, Coordinate> thisChangePointCache = new LinkedHashMap<Long, Coordinate>() {

        /** serialVersionUID */
        private static final long serialVersionUID = 1277795218777240552L;

        @Override
        protected boolean removeEldestEntry(Map.Entry<Long, Coordinate> eldest) {
            return size() == 10000;
        }
    };
    long cnt = 0;
    Set<String> deletes = Sets.newHashSet();
    Multimap<String, SimpleFeature> insertsByParent = HashMultimap.create();
    while (changes.hasNext()) {
        Change change = changes.next();
        final String featurePath = featurePath(change);
        if (featurePath == null) {
            // ignores relations
            continue;
        }
        final String parentPath = NodeRef.parentPath(featurePath);
        if (Change.Type.delete.equals(change.getType())) {
            cnt++;
            deletes.add(featurePath);
        } else {
            final Primitive primitive = change.getNode().isPresent() ? change.getNode().get() : change.getWay().get();
            final Geometry geom = parseGeometry(geogig, primitive, thisChangePointCache);
            if (geom instanceof Point) {
                thisChangePointCache.put(Long.valueOf(primitive.getId()), ((Point) geom).getCoordinate());
            }
            SimpleFeature feature = toFeature(primitive, geom);
            if (featureFilter == null || featureFilter.intersects((Envelope) feature.getBounds())) {
                insertsByParent.put(parentPath, feature);
                cnt++;
            }
        }
    }
    for (String parentPath : insertsByParent.keySet()) {
        Collection<SimpleFeature> features = insertsByParent.get(parentPath);
        if (features.isEmpty()) {
            continue;
        }
        Iterator<? extends Feature> iterator = features.iterator();
        ProgressListener listener = new DefaultProgressListener();
        List<org.locationtech.geogig.api.Node> insertedTarget = null;
        Integer collectionSize = Integer.valueOf(features.size());
        workTree.insert(parentPath, iterator, listener, insertedTarget, collectionSize);
    }
    if (!deletes.isEmpty()) {
        workTree.delete(deletes.iterator());
    }
    return cnt;
}
Also used : Node(org.locationtech.geogig.osm.internal.history.Node) Envelope(com.vividsolutions.jts.geom.Envelope) LinkedHashMap(java.util.LinkedHashMap) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Entry(java.util.Map.Entry) Primitive(org.locationtech.geogig.osm.internal.history.Primitive) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) Change(org.locationtech.geogig.osm.internal.history.Change) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(com.vividsolutions.jts.geom.Geometry) Repository(org.locationtech.geogig.repository.Repository) ProgressListener(org.locationtech.geogig.api.ProgressListener) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

Point (com.vividsolutions.jts.geom.Point)48 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Geometry (com.vividsolutions.jts.geom.Geometry)15 Test (org.junit.Test)12 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)11 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)10 Polygon (com.vividsolutions.jts.geom.Polygon)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)4 ParseException (com.vividsolutions.jts.io.ParseException)4 ArrayList (java.util.ArrayList)4 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 StringReader (java.io.StringReader)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3