GeometryFactory geomFactory = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[] { edge.getFromVertex().getCoordinate(), edge.getToVertex().getCoordinate() }; edgeGeom = GeometryUtils.getGeometryFactory().createLineString(coordinates); hasGeom = false; vvAttrs.color = null; vvAttrs.label = null; Point point = geomFactory.createPoint(new Coordinate(vertex.getLon(), vertex.getLat())); boolean render = evRenderer.renderVertex(vertex, vvAttrs); if (!render) context.graphics.draw(shape); if (vvAttrs.label != null && lineWidth > 6.0f && context.bbox.contains(point.getCoordinate())) { context.graphics.setColor(Color.BLACK); int labelWidth = largeFontMetrics.stringWidth(vvAttrs.label); double x = tilePoint.getX(); if (x + labelWidth > context.tileWidth) x -= labelWidth; context.graphics.drawString(vvAttrs.label, (float) x, (float) tilePoint.getY());
/** projected distance from stop to another stop, in latitude degrees */ private static double distance (Vertex tstop, Vertex tstop2, double xscale) { // use JTS internal tools wherever possible return new Coordinate(tstop.getLon() * xscale, tstop.getLat()).distance(new Coordinate(tstop2.getLon() * xscale, tstop2.getLat())); }
private Geometry removeDuplicatePoints(Geometry routeGeometry) { List<Coordinate> coords = new ArrayList<Coordinate>(); Coordinate last = null; for (Coordinate c : routeGeometry.getCoordinates()) { if (!c.equals(last)) { last = c; coords.add(c); } } if (coords.size() < 2) { return null; } Coordinate[] coordArray = new Coordinate[coords.size()]; return routeGeometry.getFactory().createLineString(coords.toArray(coordArray)); }
private static SimpleFeature createFeature(SimpleFeatureType type, GeoCoding geoCoding, int pointIndex, float lat, float lon, double data) { PixelPos pixelPos = geoCoding.getPixelPos(new GeoPos(lat, lon), null); if (!pixelPos.isValid()) { return null; } SimpleFeatureBuilder fb = new SimpleFeatureBuilder(type); GeometryFactory gf = new GeometryFactory(); /*0*/ fb.add(gf.createPoint(new Coordinate(pixelPos.x, pixelPos.y))); /*1*/ fb.add(gf.createPoint(new Coordinate(lon, lat))); /*2*/ fb.add(data); return fb.buildFeature(String.format("ID%08d", pointIndex)); }
tb.add("integer", Integer.class); GeometryFactory gf = new GeometryFactory(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType()); DefaultFeatureCollection secondFeatures = new DefaultFeatureCollection(null, b .getFeatureType()); firstArray[0] = new Coordinate(0, 0); firstArray[1] = new Coordinate(1, 0); firstArray[2] = new Coordinate(1, 1); firstArray[3] = new Coordinate(0, 1); firstArray[4] = new Coordinate(0, 0); LinearRing shell = gf.createLinearRing(firstArray); b.add(gf.createPolygon(shell, null)); b.add(0); Coordinate centre = ((Polygon) secondFeatures.features().next().getDefaultGeometry()) .getCentroid().getCoordinate(); Point p = gf.createPoint(centre); b.add(p); SimpleFeatureIterator iterator = output.features(); Geometry expected = (Geometry) features.features().next().getDefaultGeometry(); SimpleFeature sf = iterator.next(); assertTrue(expected.equals((Geometry) sf.getDefaultGeometry()));
if (envelope.isNull()) { return createPoint((CoordinateSequence)null); if (envelope.getMinX() == envelope.getMaxX() && envelope.getMinY() == envelope.getMaxY()) { return createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY())); if (envelope.getMinX() == envelope.getMaxX() || envelope.getMinY() == envelope.getMaxY()) { return createLineString(new Coordinate[]{ new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()) }); return createPolygon(createLinearRing(new Coordinate[]{ new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMinY()) }), null);
/** * Creates an elliptical {@link Polygon}. * If the supplied envelope is square the * result will be a circle. * * @return an ellipse or circle */ public Polygon createEllipse() { Envelope env = dim.getEnvelope(); double xRadius = env.getWidth() / 2.0; double yRadius = env.getHeight() / 2.0; double centreX = env.getMinX() + xRadius; double centreY = env.getMinY() + yRadius; Coordinate[] pts = new Coordinate[nPts + 1]; int iPt = 0; for (int i = 0; i < nPts; i++) { double ang = i * (2 * Math.PI / nPts); double x = xRadius * Math.cos(ang) + centreX; double y = yRadius * Math.sin(ang) + centreY; pts[iPt++] = coord(x, y); } pts[iPt] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly); } /**
public ShapeValue(Envelope e) { GeometryFactory gFactory = new GeometryFactory(); Coordinate[] pts = { new Coordinate(e.getMinX(), e.getMinY()), new Coordinate(e.getMaxX(), e.getMinY()), new Coordinate(e.getMaxX(), e.getMaxY()), new Coordinate(e.getMinX(), e.getMaxY()), new Coordinate(e.getMinX(), e.getMinY()) }; value = gFactory.createPolygon(gFactory.createLinearRing(pts), null); }
@Override public SimpleFeature interpretLine(String[] tokens, SimpleFeatureBuilder builder, SimpleFeatureType simpleFeatureType) throws IOException, ConversionException, TransformException { int attributeIndex = 0; for (int columnIndex = 0; columnIndex < tokens.length; columnIndex++) { String token = tokens[columnIndex]; if (columnIndex == latIndex) { lat = Double.parseDouble(token); } else if (columnIndex == lonIndex) { lon = Double.parseDouble(token); } setAttributeValue(builder, simpleFeatureType, attributeIndex, token); attributeIndex++; } builder.set("geometry", new GeometryFactory().createPoint(new Coordinate(lon, lat))); String featureId = getFeatureId(tokens); return builder.buildFeature(featureId); }
GeometryFactory gf = new GeometryFactory(); Coordinate dropPoint = new Coordinate(lon, lat); pathToStreetCoords[0] = dropPoint; pathToStreetCoords[1] = origin.getCoordinate(); LineString pathToStreet = gf.createLineString(pathToStreetCoords); coords = circleShape.getCoordinates(); geometryJSON.write(gf.createMultiPoint(coords), sw); LOG.debug("done"); } else if (output.equals(SIsochrone.RESULT_TYPE_SHED)) {
int nSide = nPts / 4; if (nSide < 1) nSide = 1; double XsegLen = dim.getEnvelope().getWidth() / nSide; double YsegLen = dim.getEnvelope().getHeight() / nSide; double x = env.getMinX() + i * XsegLen; double y = env.getMinY(); pts[ipt++] = coord(x, y); pts[ipt++] = coord(x, y); pts[ipt++] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly);
@SuppressWarnings("unchecked") public void mouseClicked() { Envelope screenEnv = new Envelope(new Coordinate(mouseX, mouseY)); screenEnv.expandBy(4, 4); Envelope env = new Envelope(toModelX(screenEnv.getMinX()), toModelX(screenEnv.getMaxX()), toModelY(screenEnv.getMinY()), toModelY(screenEnv.getMaxY())); List<Vertex> nearby = (List<Vertex>) vertexIndex.query(env); selector.verticesSelected(nearby); drawLevel = DRAW_ALL; }
public void testExecutePoint() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("featureType"); tb.add("geometry", Geometry.class); tb.add("integer", Integer.class); GeometryFactory gf = new GeometryFactory(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType()); for (int i = 0; i < 2; i++) { b.add(gf.createPoint(new Coordinate(i, i))); b.add(i); features.add(b.buildFeature(i + "")); } Double distance = new Double(500); BufferFeatureCollection process = new BufferFeatureCollection(); SimpleFeatureCollection output = process.execute(features, distance, null); assertEquals(2, output.size()); SimpleFeatureIterator iterator = output.features(); for (int i = 0; i < 2; i++) { Geometry expected = gf.createPoint(new Coordinate(i, i)).buffer(distance); SimpleFeature sf = iterator.next(); assertTrue(expected.equals((Geometry) sf.getDefaultGeometry())); } }
BikeRentalStationService bikeRentalService = graph.getService( BikeRentalStationService.class, true); Envelope envelope = new Envelope(); long osmId = area.parent.getId(); I18NString creativeName = wayPropertySet.getCreativeNameForWay(area.parent); for (Ring ring : area.outermostRings) { for (OSMNode node : ring.nodes) { envelope.expandToInclude(new Coordinate(node.lon, node.lat)); bikePark.x = (envelope.getMinX() + envelope.getMaxX()) / 2; bikePark.y = (envelope.getMinY() + envelope.getMaxY()) / 2; bikeRentalService.addBikePark(bikePark);
public SimpleFeature createPoint(final Coord coordinate, final Object[] attributeValues, final String id) { Point p = this.fac.createPoint(new Coordinate(coordinate.getX(), coordinate.getY())); this.builder.add(p); for (int i = 0; i < attributeValues.length; i++) { Object value = attributeValues[i]; this.builder.add(value); } return this.builder.buildFeature(id); }
tb.add("integer", Integer.class); GeometryFactory gf = new GeometryFactory(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType()); for (int numFeatures = 0; numFeatures < 5; numFeatures++) { Coordinate array[] = new Coordinate[4]; int j = 0; for (int i = 0 + numFeatures; i < 4 + numFeatures; i++) { array[j] = new Coordinate(i, i); j++; b.add(gf.createLineString(array)); b.add(0); features.add(b.buildFeature(numFeatures + "")); int j = 0; for (int i = 0 + numFeatures; i < 4 + numFeatures; i++) { array[j] = new Coordinate(i, i); j++; Geometry expected = gf.createLineString(array).buffer(distance); SimpleFeature sf = iterator.next(); assertTrue(expected.equals((Geometry) sf.getDefaultGeometry()));
SimpleFeatureType ft = b.buildFeatureType(); GeometryFactory geofac = new GeometryFactory(); LinearRing lr = geofac.createLinearRing(new Coordinate[]{new Coordinate(0,0),new Coordinate(0,1),new Coordinate(1,1),new Coordinate(0,0)}); Polygon p = geofac.createPolygon(lr,null); MultiPolygon mp = geofac.createMultiPolygon(new Polygon[]{p}); Collection<SimpleFeature> features = new ArrayList<SimpleFeature>(); features.add(SimpleFeatureBuilder.build(ft, new Object[]{mp,"test_name"},"fid")); Geometry g0 = (Geometry) features.iterator().next().getDefaultGeometry(); SimpleFeatureIterator it1 = fts1.features(); SimpleFeature ft1 = it1.next(); Geometry g1 = (Geometry) ft1.getDefaultGeometry(); Assert.assertEquals(g0.getCoordinates().length, g1.getCoordinates().length);
final GeometryFactory gf = new GeometryFactory(); points.add(new Coordinate(-10, -10)); points.add(new Coordinate(-10, 10)); points.add(new Coordinate(10, 10)); points.add(new Coordinate(10, -10)); points.add(new Coordinate(-10, -10)); final Polygon polygon = gf.createPolygon(new LinearRing(new CoordinateArraySequence(points .toArray(new Coordinate[points.size()])), gf), null); final Coordinate coord = new Coordinate(0, 0); final Point point = gf.createPoint(coord); System.out.println(point.within(polygon));
static public Polygon toPolygon(Envelope env, int SRID) { Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(env.getMinX(), env.getMinY()); coords[1] = new Coordinate(env.getMinX(), env.getMaxY()); coords[2] = new Coordinate(env.getMaxX(), env.getMaxY()); coords[3] = new Coordinate(env.getMaxX(), env.getMinY()); coords[4] = new Coordinate(env.getMinX(), env.getMinY()); LinearRing shell = geomFactory.createLinearRing(coords); Polygon pg = geomFactory.createPolygon(shell, null); pg.setSRID(SRID); return pg; }
protected LineString horizontalBisector(Geometry geometry) { Envelope envelope = geometry.getEnvelopeInternal(); // Assert: for areas, minx <> maxx double avgY = avg(envelope.getMinY(), envelope.getMaxY()); return factory.createLineString(new Coordinate[] { new Coordinate(envelope.getMinX(), avgY), new Coordinate(envelope.getMaxX(), avgY) }); }