@Test @Category(UnitTest.class) public void clipWithLineTouchingTop() { Point[] linePoints = { GeometryFactory.createPoint(-90.0, 0.002), GeometryFactory.createPoint(-90.0, 0.0) }; LineString line = GeometryFactory.createLineString(linePoints); { Bounds bbox = new Bounds(-180.0, -90.0, 0.0, 0.0); Geometry g = line.clip(bbox); Assert.assertNull(g); } }
@Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof LineString && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof LineString) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; }
LineStringImpl extends GeometryImpl implements WritableLineString { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof LineString && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof LineString) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } }
LineStringImpl extends GeometryImpl implements WritableLineString { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof LineString && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof LineString) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } LineStringImpl();   LineStringImpl(Map<String, String> attributes);   LineStringImpl(Point... points); }
LineStringImpl extends GeometryImpl implements WritableLineString { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof LineString && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof LineString) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } LineStringImpl();   LineStringImpl(Map<String, String> attributes);   LineStringImpl(Point... points); static Class[] getClasses(); @Override void addPoint(Point p); @Override WritableGeometry createWritableClone(); @Override void filter(PointFilter pf); @Override int getNumPoints(); @Override Point getPoint(int i); @Override Vector<Point> getPoints(); @Override void setPoints(Collection<Point> points); @Override boolean isValid(); @Override void read(DataInputStream stream); @Override void write(DataOutputStream stream); @Override Type type(); @Override void fromJTS(com.vividsolutions.jts.geom.LineString jtsLine); @Override com.vividsolutions.jts.geom.LineString toJTS(); @Override Bounds getBounds(); @Override void addPoint(double x, double y); @Override boolean isEmpty(); @Override Geometry clip(Polygon geom); }
LineStringImpl extends GeometryImpl implements WritableLineString { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof LineString && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof LineString) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } LineStringImpl();   LineStringImpl(Map<String, String> attributes);   LineStringImpl(Point... points); static Class[] getClasses(); @Override void addPoint(Point p); @Override WritableGeometry createWritableClone(); @Override void filter(PointFilter pf); @Override int getNumPoints(); @Override Point getPoint(int i); @Override Vector<Point> getPoints(); @Override void setPoints(Collection<Point> points); @Override boolean isValid(); @Override void read(DataInputStream stream); @Override void write(DataOutputStream stream); @Override Type type(); @Override void fromJTS(com.vividsolutions.jts.geom.LineString jtsLine); @Override com.vividsolutions.jts.geom.LineString toJTS(); @Override Bounds getBounds(); @Override void addPoint(double x, double y); @Override boolean isEmpty(); @Override Geometry clip(Polygon geom);  }