How to import geojson to arcgis layer in .net?
I want to convert geojson file to featurelayer in arcgis programmatically using arcgis pro sdk .Net
Solved! Go to Solution.
Sorry. It must be like this:
var featureClassUri = new Uri(featureClassPath);
//Define the Feature Layer's parameters.
var layerParams = new FeatureLayerCreationParams(featureClassUri)
{
//Set visibility
IsVisible = true,
};
Hi,
You can use JSONToFeatures geoprocessing tool to convert your data to featureclass then create layer from it. To call geoprocessing you can use code below (for point features):
var parameters = Geoprocessing.MakeValueArray(geoJSONPath, featureClassPath, "POINT");
var gpResult = await Geoprocessing.ExecuteToolAsync("conversion.JSONToFeatures", parameters,
null, CancelableProgressor.None, GPExecuteToolFlags.None);
Change 1 line 3 parameter to your data type
To create layer use another piece of code:
//Define the Feature Layer's parameters.
var layerParams = new FeatureLayerCreationParams(featureClassPath)
{
//Set visibility
IsVisible = true,
};
//Create the layer with the feature layer parameters and add it to the active map
var createdFC = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
1.
How can I filll "featureClass" parameters?
I dont't want make any feature class and gdb using arcgis pro GUI.
Can I create empty featureclass?
2. If my data feature is LOCATION, just fill "LOCATION" in the "POINT" place?
1. Do you mean "featureClassPath"? You can specify shapefile path or use default project gdb and specify prefix for FeatureClass name. You don't need create featureclass. It will be created by tool.
2. JSONToFeatures geometry_type parameter can be one of these:
So, I think POINT is what you need.
https://pro.arcgis.com/en/pro-app/latest/tool-reference/conversion/json-to-features.htm
For example, to specify featureclass path you can use code below:
string featureClassPath = Path.Combine(Project.Current.DefaultGeodatabasePath, "Locations");
I tested by making feature class, It successed
Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("C:\\Users\\hello\\Documents\\ArcGIS\\Projects\\MyProject1\\MyProject1.gdb")));
using (FeatureClass featureClass = gdb.OpenDataset<FeatureClass>("test"))
{
var parameters = Geoprocessing.MakeValueArray("./result.json", featureClass, "POINT");
var gpResult = Geoprocessing.ExecuteToolAsync("conversion.JSONToFeatures", parameters,
null, CancelableProgressor.None, GPExecuteToolFlags.None);
//Define the Feature Layer's parameters.
var layerParams = new FeatureLayerCreationParams(featureClass)
{
//Set visibility
IsVisible = true,
};
//Create the layer with the feature layer parameters and add it to the active map
var createdFC = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
}
But, when I use string featureClasssPath, error .
I attached the error image
Sorry. It must be like this:
var featureClassUri = new Uri(featureClassPath);
//Define the Feature Layer's parameters.
var layerParams = new FeatureLayerCreationParams(featureClassUri)
{
//Set visibility
IsVisible = true,
};
Thanks, I solved it! 😄