public void createArc() { List<Point> points = drawingPane.getDrawObjectsAsGeoPoints(); ApplicationContainer<?> appCont = digitizerModule.getApplicationContainer(); if (points.size() >= 3) { try { Curve curve = GeometryUtils.calcCircleCoordinates( points.get(0).getPosition(), getRadius(), getNoOfVertices(), points.get(1).getPosition(), points.get(2).getPosition(), points.get(1).getCoordinateSystem()); MapModel mapModel = appCont.getMapModel(null); Layer layer = mapModel.getLayersSelectedForAction(MapModel.SELECTION_EDITING).get(0); FeatureAdapter featureAdapter = (FeatureAdapter) layer.getDataAccess().get(0); FeatureType ft = featureAdapter.getSchema(); Feature feat = featureAdapter.getDefaultFeature(ft.getName()); feat = feat.cloneDeep(); QualifiedName geomProperty = ft.getGeometryProperties()[0].getName(); feat.getProperties(geomProperty)[0].setValue(curve); Command cmd = new InsertFeatureCommand(featureAdapter, feat); appCont.getCommandProcessor().executeSychronously(cmd, true); } catch (Exception ex) { LOG.logError(ex); DialogFactory.openErrorDialog( appCont.getViewPlatform(), DrawArcDialog.this, Messages.getMessage(getLocale(), "$MD11628"), Messages.getMessage(getLocale(), "$MD11629"), ex); } } }
/** * Method getNames * * @param rootfeat feature where starting the search * @param name name of the feature to search for * @return ArrayList<String> */ private Feature findFeature(Feature rootfeat, String name) { Object[] fp = rootfeat.getProperties(); // find out subcollections for (int i = 0; i < fp.length; i++) { Object o = fp[i]; if (o instanceof FeatureCollection) { FeatureCollection fc = (FeatureCollection) o; Feature[] feats = fc.getAllFeatures(); for (int j = 0; j < feats.length; j++) // foreach feature in the collection { if (feats[j].getFeatureType().getProperty(name) != null) // if it's ok, return it { return feats[j]; } // else perform a subsearch Feature find = findFeature(feats[j], name); if (find != null) { return find; } } } } return null; }
private boolean isTargetCRS(Feature feature, CoordinateSystem targetCRS) throws CRSTransformationException, GeometryException { FeatureProperty[] fp = feature.getProperties(); for (int i = 0; i < fp.length; i++) { if (fp[i].getValue() instanceof Geometry) { Geometry geom = (Geometry) fp[i].getValue(); if (!targetCRS.equals(geom.getCoordinateSystem())) { LOG.logInfo(geom.getCoordinateSystem().getIdentifier()); LOG.logInfo(" - " + targetCRS.getIdentifier()); return false; } } else if (fp[i].getValue() instanceof Feature) { if (!isTargetCRS((Feature) fp[i].getValue(), targetCRS)) { return false; } } } return true; }