📄 esrishapeexport.java
字号:
/** * Separates the graphics from the OMGraphicList into Polygon, * Polyline and Point lists, then passes the desired shape lists * to their respective export functions to be added to an * EsriLayer of the same type and prepared for export. OMGraphics * that are on sublists within the top-level OMGraphicList will be * simply written to the appropriate list at the top level of that * list. They will be handled as multi-part geometries. * <p> * * Separating the graphics into the three types is necessary due * to shape file specification limitations which will only allow * shape files to be of one type. * <P> * * For OMGraphicLists that are actually EsriGraphicLists, this * export method will be redirected to a different method that * will handle sub-OMGraphicLists as multi-part geometries. * <P> * * If you want to write out multi-part geometries and have a * regular OMGraphicList, you have to convert them to * EsriGraphicLists first (and OMGraphics to EsriGraphics), which * forces you to group shapes into like types (points, polylines * and polygons). */ public void export() { OMGraphicList list = getGraphicList(); if (list == null) { Debug.error("EsriShapeExport: no graphic list to export!"); return; } export(list, null, true); } /** * A counter for graphics that are not RENDERTYPE_LATLON. */ int badGraphics; /** * This method is intended to allow embedded OMGraphicLists to be * handled. The record should be set if the list is an embedded * list, reusing a record from the top level interation. Set the * record to null at the top level iteration to cause the method * to fetch the record from the masterDBF, if it exists. * * @param list the OMGraphicList to write * @param record the record for the current list, used if the list * is actually a multipart geometry for the overall list. * May be null anyway, though. * @deprecated use export(OMGraphicList, ArrayList, boolean) * instead. * @see #export(OMGraphicList list, ArrayList record, boolean * writeFiles) */ protected void export(OMGraphicList list, ArrayList record) { export(list, record, true); } /** * This method is intended to allow embedded OMGraphicLists to be * handled. The record should be set if the list is an embedded * list, reusing a record from the top level interation. Set the * record to null at the top level iteration to cause the method * to fetch the record from the masterDBF, if it exists. If the * list is an EsriGraphicList, then the export for * EsriGraphicLists will be called. The DbfTableModel for the list * should be stored in the DBF_ATTRIBUTE attribute of the * EsriGraphicList. * * @param list the OMGraphicList to write. * @param masterRecord the record for the current list, used if * the list is actually a multipart geometry for the * overall list. May be null anyway, though. * @param writeFiles Flag to note when this method is being called * iteratively, which is when record is not null. If it is * iterative, then the writing of the files should not be * performed on this round of the method call. */ protected void export(OMGraphicList list, ArrayList masterRecord, boolean writeFiles) { badGraphics = 0; if (list == null) { return; } else if (list instanceof EsriGraphicList) { export((EsriGraphicList) list); return; } int dbfIndex = 0; // parse the graphic list and fill the individual lists with // the appropriate shape types Iterator it = list.iterator(); while (it.hasNext()) { OMGraphic dtlGraphic = (OMGraphic) it.next(); // Reset the record to the master flag record, which will // cause a new record to be read for the top level list // contents, but duplicate the current masterRecord for // iterative contents. ArrayList record = masterRecord; if (record == null) { record = getMasterDBFRecord(dbfIndex++); } // If we have an OMGraphicList, interate through that one // as well. We're not handling multi-part geometries yet. if (dtlGraphic instanceof OMGraphicList) { if (DEBUG) Debug.output("ESE: handling OMGraphicList"); export((OMGraphicList) dtlGraphic, record, false); continue; } // check to be sure the graphic is rendered in LAT/LON if (dtlGraphic.getRenderType() != RENDERTYPE_LATLON) { badGraphics++; continue; } if (dtlGraphic instanceof OMPoly) { OMPoly omPoly = (OMPoly) dtlGraphic; // verify that this instance of OMPoly is a polygon if (isPolygon(omPoly)) { if (DEBUG) Debug.output("ESE: handling OMPoly polygon"); addPolygon(dtlGraphic, record); } // if it is not it must be a polyline and therefore // added to the line list else { if (DEBUG) Debug.output("ESE: handling OMPoly line"); addLine(dtlGraphic, record); } } // (end)if (dtlGraphic instanceof OMPoly) // add all other fully enclosed graphics to the polyList else if (dtlGraphic instanceof OMRect) { if (DEBUG) Debug.output("ESE: handling OMRect"); addPolygon((OMGraphic) EsriPolygonList.convert((OMRect) dtlGraphic), record); } else if (dtlGraphic instanceof OMCircle) { if (DEBUG) Debug.output("ESE: handling OMCircle"); addPolygon((OMGraphic) EsriPolygonList.convert((OMCircle) dtlGraphic, projection), record); } else if (dtlGraphic instanceof OMRangeRings) { if (DEBUG) Debug.output("ESE: handling OMRangeRings"); export(EsriPolygonList.convert((OMRangeRings) dtlGraphic, projection), record, false); } // add lines to the lineList else if (dtlGraphic instanceof OMLine) { if (DEBUG) Debug.output("ESE: handling OMLine"); addLine((OMGraphic) EsriPolylineList.convert((OMLine) dtlGraphic), record); } // add points to the pointList else if (dtlGraphic instanceof OMPoint) { if (DEBUG) Debug.output("ESE: handling OMPoint"); addPoint(dtlGraphic, record); } } // (end)for (int i = 0; i < dtlGraphicList.size(); i++) if (badGraphics > 0) { // Information popup provider, it's OK that this gets // dropped. DrawingToolRenderException.notifyUserOfNonLatLonGraphics(badGraphics); } if (!writeFiles) { // Punch the stack back up so that the initial call will // write the files. return; } boolean needConfirmation = false; // call the file chooser if no path is given if (filePath == null) { filePath = getFilePathFromUser(); if (filePath == null) { return; // User cancelled. } needConfirmation = true; } if (DEBUG) Debug.output("ESE: writing files..."); boolean needTypeSuffix = false; // (end)if (filePath == null) call the appropriate methods to // set up the shape files of their respective types if (polyList != null) { eseInterfaces.add(new ESEInterface(polyList, filePath, null)); needTypeSuffix = true; } if (lineList != null) { eseInterfaces.add(new ESEInterface(lineList, filePath, (needTypeSuffix ? "Lines" : null))); needTypeSuffix = true; } if (pointList != null) { eseInterfaces.add(new ESEInterface(pointList, filePath, (needTypeSuffix ? "Pts" : null))); } if (needConfirmation) { showGUI(); } else { writeFiles(); } } /** * Writes out EsriGraphicLists as shape files, assumes that the * DbfTableModel representing the attribute data for the list * objects is stored in the appObject member variable of the * EsriGraphicList. This export handles multi-part geometries, * because it's assumed that the sorting of the graphic types have * been handled and that any sub-lists are meant to be multi-part * geometries. If the filePath hasn't been set in the * EsriShapeExport class, the user will be asked to provide it. */ protected void export(EsriGraphicList egList) { Object obj = egList.getAttribute(DBF_ATTRIBUTE); // Backward compatibility if (obj == null) { egList.getAppObject(); } if (obj == null) { egList.putAttribute(DBF_ATTRIBUTE, getMasterDBF()); // egList.setAppObject(getMasterDBF()); } eseInterfaces.add(new ESEInterface(egList, filePath, null)); writeFiles(); } /** * The the Iterator of ESEIterators. */ protected Iterator getInterfaces() { return eseInterfaces.iterator(); } /** * Just write the files from the ESEInterfaces. */ protected void writeFiles() { Iterator it = getInterfaces(); while (it.hasNext()) { ((ESEInterface) it.next()).write(); } } protected JFrame frame = null; /** * Show the GUI for saving the Shape files. */ public void showGUI() { if (frame == null) { frame = new JFrame("Saving Shape Files"); frame.getContentPane().add(getGUI(), BorderLayout.CENTER); // frame.setSize(400, 300); frame.pack(); } frame.setVisible(true); } /** * Hide the Frame holding the GUI. */ public void hideGUI() { if (frame != null) { frame.setVisible(false); } } /** * Create the GUI for managing the different ESEIterators. */ public Component getGUI() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel interfacePanel = new JPanel(); interfacePanel.setLayout(new GridLayout(0, 1)); Iterator interfaces = getInterfaces(); int count = 0; while (interfaces.hasNext()) { interfacePanel.add(((ESEInterface) interfaces.next()).getGUI()); count++; } panel.add(interfacePanel, BorderLayout.CENTER); if (count > 1) { JLabel notification = new JLabel(" " + count + " Shape file sets needed:"); panel.add(notification, BorderLayout.NORTH); } JButton saveButton = new JButton("Save"); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { writeFiles(); hideGUI(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { hideGUI(); } }); JPanel controlPanel = new JPanel(); controlPanel.add(saveButton); controlPanel.add(cancelButton); panel.add(controlPanel, BorderLayout.SOUTH); return panel; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -