private int getDisconinuityDirection(CoordinateSequence cs) { double lastOrdinate = cs.getOrdinate(0, ordinateIdx); for (int i = 0; i < cs.size(); i++) { double ordinate = cs.getOrdinate(i, ordinateIdx); if (Math.abs(ordinate - lastOrdinate) > wrapLimit) { if (ordinate > lastOrdinate) return WEST_TO_EAST; else if (ordinate < lastOrdinate) return EAST_TO_WEST; } lastOrdinate = ordinate; } return NOWRAP; }
public static int D(CoordinateSequence cs) { if (cs instanceof CoordinateAccess) { return ((CoordinateAccess) cs).getDimension(); } if (cs.size() > 0) { return Double.isNaN(cs.getCoordinate(0).z) ? 2 : 3; } return 3; }
static void encodeCoords(Element e, CoordinateSequence coords, PrintHandler output) throws IOException { if ((coords == null) || (coords.size() == 0)) { return; } encodeCoords(e, coords.toCoordinateArray(), output); }
private void writePoint(Point pt, OutStream os) throws IOException { if (pt.getCoordinateSequence().size() == 0) throw new IllegalArgumentException("Empty Points cannot be represented in WKB"); writeByteOrder(os); writeGeometryType(DB2WKBConstants.wkbPoint2D, os); writeCoordinateSequence(pt.getCoordinateSequence(), false, os); }
private void extractSegments(CoordinateSequence cs) { for (int i = 0; i < cs.size() - 1; i++) { segments.add(new Segment(cs.getX(i), cs.getY(i), cs.getX(i + 1), cs.getY(i + 1))); } }
static DirectPosition[] positions(LineString line) { CoordinateSequence coordinates = line.getCoordinateSequence(); DirectPosition[] dps = new DirectPosition[coordinates.size()]; double x; double y; for (int i = 0; i < dps.length; i++) { x = coordinates.getOrdinate(i, 0); y = coordinates.getOrdinate(i, 1); dps[i] = new DirectPosition2D(x, y); } return dps; }
public void init(CoordinateSequence cs) { clear(); for (int i = 0; i < cs.size(); i++) { add(cs.getOrdinate(i, 0), cs.getOrdinate(i, 1)); } }
protected void write(Encoder output, CoordinateSequence coordseq) throws IOException { int dim = coordseq.getDimension(); // if(dim>2) { // throw new IllegalArgumentException("only supports 2d geometry now ("+dim+")"); // } for (int i = 0; i < coordseq.size(); i++) { output.write(coordseq.getOrdinate(i, 0), coordseq.getOrdinate(i, 1)); } }
List<?> toList(CoordinateSequence cs) { BasicDBList l = new BasicDBList(); for (int i = 0; i < cs.size(); i++) { BasicDBList m = new BasicDBList(); m.add(cs.getX(i)); m.add(cs.getY(i)); l.add(m); } return l; }
@Test public void testToGeoemtry() { DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84; // straight up Polygon polygon = JTS.toGeometry(new Envelope(-10, 10, -10, 10)); assertEquals(5, polygon.getExteriorRing().getCoordinateSequence().size()); // bounding box polygon = JTS.toGeometry((BoundingBox) new ReferencedEnvelope(-10, 10, -10, 10, crs)); assertEquals(5, polygon.getExteriorRing().getCoordinateSequence().size()); }
@Test public void testDecimateOpenTriangle() throws Exception { LineString g = gf.createLineString(csf.create(new double[] {0, 0, 0, 2, 2, 2, 0, 0})); assertTrue(g.isValid()); Decimator d = new Decimator(3, 3); d.decimateTransformGeneralize(g, new AffineTransform2D(new AffineTransform())); g.geometryChanged(); assertTrue(g.isValid()); assertEquals(4, g.getCoordinateSequence().size()); }
/** http://jira.codehaus.org/browse/GEOT-2937 */ @Test public void testDecimatePseudoRing() { // a long rectangle made of 3 coordinates LineString g = gf.createLineString(csf.create(new double[] {0, 0, 0, 10, 0, 0})); assertTrue(g.isValid()); Decimator d = new Decimator(4, 4); d.decimate(g); g.geometryChanged(); assertTrue(g.isValid()); assertEquals(3, g.getCoordinateSequence().size()); }
/** http://jira.codehaus.org/browse/GEOT-1923 */ @Test public void testDecimateRingEnvelope() { // acute triangle LinearRing g = gf.createLinearRing(csf.create(new double[] {0, 0, 0, 10, 2, 10, 2, 0, 0, 0})); assertTrue(g.isValid()); Decimator d = new Decimator(20, 20); d.decimate(g); g.geometryChanged(); assertTrue(g.isValid()); assertEquals(4, g.getCoordinateSequence().size()); }
/** http://jira.codehaus.org/browse/GEOT-1923 */ @Test public void testDecimateRing() { // a long rectangle made of 5 coordinates LinearRing g = gf.createLinearRing(csf.create(new double[] {0, 0, 0, 10, 2, 10, 2, 0, 0, 0})); assertTrue(g.isValid()); Decimator d = new Decimator(4, 4); d.decimate(g); g.geometryChanged(); assertTrue(g.isValid()); assertEquals(4, g.getCoordinateSequence().size()); }