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");
}
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;
}
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;
}
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;
}
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;
}
Aggregations