02-10-2016 03:03 AM
HI All,
( In online )
Is there a way to force a new geometry being placed to be a simple geometry.
i.e. When placing a point we don’t want multipoints. If the user places more than one point it will ultimately become a multi-point. We want to force a simple single point.
Can the save be automated once the point is placed?
Thanks
John
Solved! Go to Solution.
02-10-2016 03:31 AM
Hi John,
are we talking about new entries or would you also need to perform updates of existing points?
02-10-2016 03:43 AM
Hi Thomas,
New Entries.
Updating is actually no problem at all because the action is different,
But for the NEW_POINT action, it doesn't limit the geometry to a single point type.
Thanks
John
02-10-2016 04:37 AM
Hi John,
out of the box there is no way to change this.
However we have several options:
public class SampleClientValidationHandler implements IValidator { public List<ValidationError> validate(List<PersistenceElement> elements) { List<ValidationError> validationErrors = new ArrayList<ValidationError>(); Feature featureToEdit = ((EditPlugin) ApplicationContext.getPluginCurator().getByName("EditPlugin")).getEditSettings().getFeature(); if(elements.size() == 0 || !featureToEdit.getName().equals("HGDN Buildings")) return validationErrors; if(elements.size()>1) validationErrors.add(new ValidationError("Only one element may be persited", true)); return validationErrors; } }
public class SampleGeometryChangeHandler : IGeometryChangeHandler { public void OnGeometryChanging(GeometryChangingContext context) { //first check if the current context is the one that you are interested in if (!context.FeatureMetadata.Name.Equals("YOURFEATURENAME", StringComparison.OrdinalIgnoreCase)) return; //it is already a simple point if (context.Geometries.Count() == 1 || context.Geometries.First().Geometry.GeometryType == GeometryType.Point || context.Geometries.First().Geometry.GeometryType == GeometryType.OrientedPoint) return; GeometryMetadata geometryOfInterest = context.Geometries.First(); GeometryMetadata resultGeometry = new GeometryMetadata(geometryOfInterest.Identifier, geometryOfInterest.Geometry); foreach (KeyValuePair<string, object> attribute in geometryOfInterest.Attributes) resultGeometry.Attributes.Add(attribute.Key, attribute.Value); if(geometryOfInterest.Geometry.GeometryType == GeometryType.GeometryCollection || geometryOfInterest.Geometry.GeometryType == GeometryType.MultiPoint) resultGeometry.Geometry = geometryOfInterest.Geometry.STGeometryN(1); context.Geometries = new List<GeometryMetadata>() { resultGeometry }; } public void OnGeometryChanged(GeometryChangedContext context) { //nothing to do here } }
03-01-2016 12:51 AM
Hi Thomas,
I am looking for option three to implement. My client doesn't want to use default capture/edit geometry behaviour. User will keyed-in X and Y coordinates along with attributes. I am able to achieve this for offline by passing JSON object to ScriptingObject.
//Offline implementation for creating point and adding in existing layer.
databaseConnector = DatabaseConnectorFactory.getInstance().getDatabaseConnector(H2DatabaseConnector.class); GPoint point = new GPoint(new GAction(UUID.randomUUID().toString()), GFeatureTypeStyleManager.getInstance().getStyle(EditSettings.DEFAULT_STYLE),data.getKey().getKey() ); point.setCustomValues(data.getValue()); databaseConnector.add(ApplicationContext.getBrowser().getActiveFeatureID().toString(), point);
Is it possible to implement something similar in ScriptingObject to achieve this for online mode?
Thanks,
Jai Ram Gaur