📄 geointersectionlayer.java
字号:
/** * Query the user for a shape file, and add the contents to the region list * or line list if a valid file is selected. */ public void addShapeFileFromUser() { String shpFileName = FileUtils.getFilePathToOpenFromUser("Pick Shape File", new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith("shp"); } public String getDescription() { return "ESRI Shape (.shp) file"; } }); if (shpFileName != null) { addShapeFile(new File(shpFileName)); } } /** * Add the data from a shape file to the region list or edge list, depending * on the content type. * * @param shpFile */ public void addShapeFile(File shpFile) { if (shpFile != null) { try { String shpFilePath = shpFile.getAbsolutePath(); String shpFileName = shpFile.getName(); DrawingAttributes da = new DrawingAttributes(); da.setSelectPaint(new Color(200, 100, 100, 200)); EsriGraphicList shapeList = EsriGraphicList.getEsriGraphicList(shpFile.toURL(), da, DbfTableModel.getDbfTableModel(new File(shpFilePath.replaceAll(".shp", ".dbf")).toURL())); if (DEBUG) Debug.output("GeoIntersectLayer(" + getName() + "): Adding shapes from " + shpFileName); JCheckBox visibilityControl = new JCheckBox("Show", true); visibilityControl.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setShapeListVisibilityForCheckbox(); repaint(); } }); JButton removeButton = new JButton("Remove"); removeButton.addActionListener(new RemoveShapesActionListener(fileDataList, shapeList)); JLabel label = new JLabel(shpFileName, JLabel.LEFT); JPanel panel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); panel.setLayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.insets = new Insets(2, 2, 2, 2); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(label, c); panel.add(label); c.weightx = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(visibilityControl, c); panel.add(visibilityControl); gridbag.setConstraints(removeButton, c); panel.add(removeButton); shapeList.putAttribute(SHAPE_FILE_NAME_ATTRIBUTE, shpFileName); shapeList.putAttribute(SHAPE_VISIBILITY_CONTROL_ATTRIBUTE, visibilityControl); shapeList.putAttribute(SHAPE_CONTROL_ATTRIBUTE, panel); int type = shapeList.getType(); if (type != EsriGraphicList.SHAPE_TYPE_POLYGON && type != EsriGraphicList.SHAPE_TYPE_POLYLINE) { fireRequestMessage("The type of shapes contained in the file\n" + shpFileName + "\nisn't handled by this layer. Choose a file that\ncontains lines or polygons."); return; } fileDataList.add(shapeList); rebuildFileListControl(); if (getProjection() != null) { doPrepare(); } } catch (MalformedURLException murle) { } } } protected void setShapeListVisibilityForCheckbox() { for (Iterator it = fileDataList.iterator(); it.hasNext();) { Object obj = it.next(); if (obj instanceof OMGraphicList) { OMGraphicList omgl = (OMGraphicList) obj; obj = omgl.getAttribute(SHAPE_VISIBILITY_CONTROL_ATTRIBUTE); if (obj != null) { omgl.setVisible(((JCheckBox) obj).isSelected()); } } } } public ExtentIndex getRegionIndex(boolean resetRegionSelection) { if (regionIndex == null) { regionIndex = new ExtentIndexImpl(); } if (resetRegionSelection) { for (Iterator reset = regionIndex.iterator(); reset.hasNext();) { shapeDA.setTo(((OMPolyRegion) reset.next()).poly); } if (DEBUG) Debug.output("GeoIntersectLayer(" + getName() + "): Reset region fills"); } return regionIndex; } protected void addToRegionIndex(OMPoly p, ExtentIndex regionIndex) { if (regionIndex.addExtent(new OMPolyRegion(p)) && DEBUG) { Debug.output("GeoIntersectLayer(" + getName() + "): Added poly region to RegionIndex"); } } protected void addToRegionIndex(OMGraphicList omgl, ExtentIndex regionIndex) { for (Iterator it = omgl.iterator(); it.hasNext();) { Object someObj = it.next(); if (someObj instanceof OMPoly) { addToRegionIndex((OMPoly) someObj, regionIndex); } else { addToRegionIndex((OMGraphicList) someObj, regionIndex); } } } public void drawingComplete(OMGraphic omg, OMAction action) { releaseProxyMouseMode(); if ((omg instanceof OMLine || omg instanceof OMPoly || omg instanceof OMPoint) && drawnList != null) { drawnList.doAction(omg, action); deselect(drawnList); doPrepare(); } else { Debug.error("GeoIntersectLayer(" + getName() + "): received " + omg + " and " + action + " with no list ready"); } // This is important!! if (editorTool != null) { editorTool.drawingComplete(omg, action); } } public OMGraphicList getDrawnIntersectorList() { return drawnList; } public boolean receivesMapEvents() { return false; } public boolean mouseOver(MapMouseEvent mme) { if (regionIndex != null) { LatLonPoint llp = mme.getLatLon(); GeoPoint geop = new GeoPoint.Impl(llp.getLatitude(), llp.getLongitude()); for (Iterator hits = Intersection.intersect(geop, regionIndex); hits.hasNext();) { OMPolyRegion ompr = (OMPolyRegion) hits.next(); ompr.poly.select(); ompr.poly.generate(getProjection()); } repaint(); } return true; } public boolean isHighlightable(OMGraphic omg) { return createPointCheck || (drawnList != null && drawnList.contains(omg)); } public String getToolTipTextFor(OMGraphic omg) { if (drawnList != null && drawnList.contains(omg)) { return super.getToolTipTextFor(omg); } else if (createPointCheck) { return "Click to create point test image mask"; } return null; } public void highlight(OMGraphic omg) { omg.setMatted(true); super.highlight(omg); } public void unhighlight(OMGraphic omg) { omg.setMatted(false); super.unhighlight(omg); } public boolean isSelectable(OMGraphic omg) { return createPointCheck || (drawnList != null && drawnList.contains(omg)); } public void select(OMGraphicList omgl) { for (Iterator it = omgl.iterator(); it.hasNext();) { OMGraphic omg = (OMGraphic) it.next(); if (drawnList != null && drawnList.contains(omg)) { super.select(omgl); } else if (createPointCheck) { intersectionResultList.add(getPointIntersectionImage(omg)); } } repaint(); } public void deselect(OMGraphicList omgl) { intersectionResultList.clear(); repaint(); } public OMGraphic getPointIntersectionImage(OMGraphic omg) { Shape s = omg.getShape(); Projection p = getProjection(); if (s != null && p != null && omg instanceof OMPoly) { Rectangle r = s.getBounds(); double x = r.getX(); double y = r.getY(); double h = r.getHeight(); double w = r.getWidth(); float[] rawll = ((OMPoly) omg).getLatLonArray(); LatLonPoint llHolder = new LatLonPoint(); Geo g = new Geo(0, 0); int[] pix = new int[(int) (h * w)]; for (double j = 0; j < h; j++) { for (double i = 0; i < w; i++) { boolean inShape = s.contains(i + x, j + y); p.inverse((int) (i + x), (int) (j + y), llHolder); g.initialize(llHolder.getLatitude(), llHolder.getLongitude()); boolean inGeo = Intersection.isPointInPolygon(g, rawll, false); int val = 0; if (inShape == inGeo) { val = 0x6200FF00; } else { val = 0x62ff0000; } pix[(int) (w * j + i)] = val; } } OMRaster omr = new OMRaster((int) x, (int) y, (int) w, (int) h, pix); omr.setSelectPaint(OMColor.clear); // omr.setSelected(true); omr.generate(p); return omr; } return SinkGraphic.getSharedInstance(); } protected JPanel getFileListControl() { if (fileListControl == null) { fileListControl = PaletteHelper.createHorizontalPanel("Shape Files Being Used for Intersections"); } return fileListControl; } public void rebuildFileListControl() { JPanel p = getFileListControl(); p.setBackground(Color.white); Color light = Color.white; Color dark = Color.LIGHT_GRAY; Color current = dark; p.removeAll(); GridBagLayout gridbag = new GridBagLayout(); p.setLayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.gridx = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; getRegionIndex(false).clear(); for (Iterator it = fileDataList.iterator(); it.hasNext();) { Object obj = it.next(); if (obj instanceof EsriGraphicList) { EsriGraphicList shapeList = (EsriGraphicList) obj; JPanel control = (JPanel) shapeList.getAttribute(SHAPE_CONTROL_ATTRIBUTE); if (control != null) { control.setBackground(current); Component[] comps = control.getComponents(); for (int i = 0; i < comps.length; i++) { comps[i].setBackground(current); } if (current == dark) current = light; else current = dark; gridbag.setConstraints(control, c); p.add(control); } addToRegionIndex(shapeList, getRegionIndex(false)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -