public static LinkedList<PreparedPolygon> load() throws IOException { URL krajeShp = Kraje.class .getResource("kraje/hranice_krajov_simpl.shp"); FileDataStore store = FileDataStoreFinder.getDataStore(krajeShp); FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store .getFeatureSource(); FeatureCollection<SimpleFeatureType, SimpleFeature> fC = featureSource .getFeatures(); FeatureIterator<SimpleFeature> iter = fC.features(); LinkedList<PreparedPolygon> list = new LinkedList<PreparedPolygon>(); try { while (iter.hasNext()) { Feature f = iter.next(); GeometryAttribute geomAttr = f.getDefaultGeometryProperty(); list.add(new PreparedPolygon((Polygonal) geomAttr.getValue())); } } finally { iter.close(); } return list; }
public ViewChangedObserver(Exporter _exporter, Collection<PreparedPolygon> _kraje, MGMap _map, int _minx, int _maxx, int _miny, int _maxy) throws IOException, SQLException { kraje = _kraje; map = _map; minx = _minx; maxx = _maxx; miny = _miny; maxy = _maxy; exporter = _exporter; // At this point exporter.conn may still be not initialized }
private static Geometry intersectionSim( PreparedGeometry pg, Geometry g2) { PreparedPolygon ppoly = (PreparedPolygon) pg; FastSegmentSetIntersectionFinder intf = ppoly.getIntersectionFinder(); Coordinate[] pts = g2.getCoordinates(); List segStrings = SegmentStringUtil.extractSegmentStrings(g2); intf.intersects(segStrings ); return g2; }
/** * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage */ public int[] rasterMaskJTS(Rectangle rect, int offsetX, int offsetY, double scalingFactor) { // create the buffered image of the size of the Rectangle int[] mask = new int[rect.width* rect.height]; GeometryFactory gf = new GeometryFactory(); // define the clipping region in full scale Coordinate[] coords = new Coordinate[]{ new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))), new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))), new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))), new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))), new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),}; Polygon geom = gf.createPolygon(gf.createLinearRing(coords)); PreparedPolygon ppol=new PreparedPolygon(geom); int numPix=rect.width*rect.height; for (Geometry p : maskGeometries) { if (ppol.intersects(p)) { Geometry pg=p.intersection(geom).buffer(0); IndexedPointInAreaLocator locator=new IndexedPointInAreaLocator(pg); int x=0; int y=0; for(int ii=0;ii<numPix;ii++){ if(ii%rect.width==0){ x=0; y++; } //Point point=gf.createPoint(new Coordinate(rect.x+x,rect.y+y)); //PreparedPoint ppoint=new PreparedPoint(point); //if(ppoint.within(pg)){ int loc=locator.locate(new Coordinate(rect.x+x,rect.y+y)); if(loc==Location.INTERIOR||loc==Location.BOUNDARY) try{ mask[x]=1; }catch(Exception e){ logger.warn(e.getMessage()+" x:"+x+" y:"+y); } } } //} } return mask; }
public PredicateEvaluatorPrepared(Geometry geometry) { this.factory = new GeometryFactory(); this.preparedPolygon = new PreparedPolygon((Polygonal) geometry); }