📄 geointersectionlayer.java
字号:
if (DEBUG) Debug.output("GeoIntersectLayer(" + getName() + "): Adding lines to main list"); list.add(fileDataList); if (DEBUG) Debug.output("GeoIntersectLayer(" + getName() + "): Adding shapes to main list"); list.generate(getProjection()); if (DEBUG) Debug.output("GeoIntersectLayer(" + getName() + "): Projected main list, returning"); return list; } protected void setRegionAsSelected(OMPolyRegion ompr) { shapeDASelected.setTo(ompr.poly); } protected GeoPath getPathFromOMGraphic(OMGraphic omg) { GeoPath path = null; if (omg instanceof OMLine) { path = getPath((OMLine) omg); } else if (omg instanceof OMPoly) { path = getPath((OMPoly) omg); } return path; } protected GeoPath getPath(OMLine oml) { return new GeoPath.Impl(oml.getLL()); } protected GeoPath getPath(OMPoly omp) { return new GeoPath.Impl(omp.getLatLonArray(), false); } /** * 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(), new File(shpFilePath.replaceAll(".shp", ".shx")).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 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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -