Hexagon Geospatial
MENU

Smart M.App

Looking for answers in regards to M.Apps, M.App Exchange or M.App Studio? Smart M.App Tech Discussion board is where you can search, ask your questions and assist others by sharing your knowledge. Join the conversation, connect, contribute and share.
Showing results for 
Search instead for 
Do you mean 
Reply
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017
Accepted Solution

GeoJson as vector input for spatial recipe?

Hi everyone,

 

I have a spatial recipe which calculates buffers around point geometries.

At the moment I upload the point features as shape files on M.App Chest. Now I tried to run the recipe with an uploaded geojson file of the same data and I get an error. Reading in the operator documentation of ERDAS Imagine I couldn't find any operator that accepts geojson as vector input.

Now I'm wondering how to feed the recipe with data that isn't uploaded as shp-file on chest in advance but is retrieved from a wfs or the selected features on a bi map... In these cases the feature format would be geojson right?

 

Regards

Marisa

Technical Evangelist
Posts: 31
Registered: ‎09-10-2015

Re: GeoJson as vector input for spatial recipe?

There are a few subtleties that need to be understood in order to achieve what I think you are trying to achieve.

 

The Features Input operator accepts both a File reference and a FeatureSubset on its input port. A FeatureSubset is a Spatial Modeler data type and like all Spatial Modeler data types, its serialization includes information about its Spatial Modeler type. Thus, although the Value embeded in its serialization can be pure GeoJSON, you cannot use GeoJSON by itself. You must wrap it with the appropriate decoration, i.e.,

 

{
"Type" : "IMAGINE.FeatureSubset",
"Value" : { <GeoJSON Feature Collection> }

}

 

It is not necessary to include additional attributes, such as geometryInfo, that you might see placed into the GeoJSON by Spatial Modeler.

 

Also, if you are attempting to actually put this serialization into a file, you cannot supply a file reference of this sort directly to Features Input because it does not know how to understand a file reference like that. You must first have the Data Input operator deserialize the JSON into a FeatureSubset as illustrated in the diagram below. 

 

 

SerializedFeatureSubsetAsFeaturesInput.PNG

Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: GeoJson as vector input for spatial recipe?

[ Edited ]

Thanks for your reply! I added the data input operator and really tried everything to make it run.

No the recipe runs fine when I test it in spatial workshop and take my json input file with following content from chest :

 

{"Type": "IMAGINE.FeatureSubset",
"Value":{
		"type":"FeatureCollection",
		"features":[{
					"type":"Feature",
					"geometry":{"coordinates":[92.165412,21.199137],"type":"Point"},
					"properties":{"id":9931,"_index":763}
					}]
		}
}

When I insert exactly these lines directly in the processing input parameters in my code the processing fails. (following code is only an extract of the input parameters):

 

 

var _GeoprocessingParam = {
                path: "api/v1/geoprocesses/" + GEOPROCESSING_MODEL_ID + "/execute",
                method: 'POST',
                entity: {
                    "Inputs": [
                    {
                        "Data": {
                            "Input": true,
                            "Type": "IMAGINE.FeatureSubset",
                            "Value":{
                            		"type":"FeatureCollection",
                            		"features":[{
                            					"type":"Feature",
                            					"geometry":{"coordinates":[92.165412,21.199137],"type":"Point"},
                            					"properties":{"id":9931,"_index":763}
                            					}]
                            		}
                            
                        },
                        "Name": "POI_layer"
                    }, {
                        "Data": {
                            "Input": true,
                            "Type": "IMAGINE.File",
                            "Value": Chest_File_ID
                        },
                        "Name": "other_layer"
                    }],
                    "Method": "Asynchronous"
                
                }
            };

 

 

So I really don't see any mistake ...

Any ideas? Or could someone test this if it is possible to add Json inline like this? I mean it should because its part of this tutorial  (or is this no longer possible?)

 

Thanks

Marisa

 

Technical Evangelist
Posts: 31
Registered: ‎09-10-2015

Re: GeoJson as vector input for spatial recipe?

If you are using something similar to the Get Input Features sub-model to feed the POI_layer input into Features Input as in the referenced example, then I would expect it to work with a JSON file reference (where the JSON file contains a FeatureSubset), Shapefile reference, or inline JSON for the FeatureSubset. Is that what you are doing?

Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: GeoJson as vector input for spatial recipe?

Yes, that's what I was trying to do. I only used the Data Input operator between the port input and the feature input operator.  I changed it to the one in the example after your post but I think it should be the same result. I don't know what the final problem was (sorry for everyone struggeling with the same issue) but finally it worked. In the end I didn't embed the FeatureCollection hardcoded. I took it from the getSelectedFeatures function  and stored it in a variable which I pass to the model. The json object itself as it is returned by the function needs to be taken as is and not a stringified version (as one might expect as you pass a string when you hardcode the model input.

So thanks for your help, somehow it pushed me into the correct direction :-)

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.