Select to view content in your preferred language

How to import geojson to arcgis layer in .net

1802
7
Jump to solution
10-18-2022 06:39 PM
SIASIA1
Emerging Contributor

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

 

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

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,
      };

View solution in original post

7 Replies
GKmieliauskas
Esri Regular Contributor

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);

 

0 Kudos
SIASIA1
Emerging Contributor

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?

0 Kudos
GKmieliauskas
Esri Regular Contributor

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:

  • POINTPoints will be converted to features.
  • MULTIPOINTMultipoints will be converted to features.
  • POLYLINEPolylines will be converted to features.
  • POLYGONPolygons will be converted to features.

 So, I think POINT is what you need.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/conversion/json-to-features.htm 

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

For example, to specify featureclass path you can use code below:

string featureClassPath = Path.Combine(Project.Current.DefaultGeodatabasePath, "Locations");
0 Kudos
SIASIA1
Emerging Contributor

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

0 Kudos
GKmieliauskas
Esri Regular Contributor

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,
      };
SIASIA1
Emerging Contributor

Thanks, I solved it! 😄

0 Kudos