GMSC Discussions

GeoMedia Smart Client community discussion board is where you can create, contribute and share information and knowledge in regards to configuring as well as working with GeoMedia Smart Client. Find your answers, share your knowledge and help build a strong GeoMedia Smart Client community.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 9
Registered: ‎01-15-2016
Accepted Solution

Multiple geometries

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

 

Community Manager
Posts: 164
Registered: ‎10-09-2015

Re: Multiple geometries

Hi John,

are we talking about new entries or would you also need to perform updates of existing points?

Thomas Anzinger
Community Manager
thomas.anzinger@hexagongeospatial.com
Occasional Contributor
Posts: 9
Registered: ‎01-15-2016

Re: Multiple geometries

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

Community Manager
Posts: 164
Registered: ‎10-09-2015

Re: Multiple geometries

Hi John,

out of the box there is no way to change this.

However we have several options:

  1. Implement a client side validation handler:
    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;
    		
    	}
    
    }
  2. Implement a GeometryChangeHandler on the server side
    You could implement a GeometryChangeHandler that removes the additional geometries or in case that it is a MultiPoint (should only happen if the geometry type is a Collection),convert the multi point into a single point and return this single point (quick and dirty - details missing for sure)::
     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
            }       
        }
  3. Implement a custom behavior using a ScriptingObject and a GeometryCaptureInstance.
    This would be the most complex solution and would bypass the default editing behavior. Depending on how complex the content is (do you have geometry validation in place,... or is it a simple save) this could also be an option.
    Only in this case you could automate the save after placing the point.
    This option would need a bit longer to implement the sample. 

 

Thomas Anzinger
Community Manager
thomas.anzinger@hexagongeospatial.com
Contributor
Posts: 37
Registered: ‎10-12-2015

Re: Multiple geometries

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