Select to view content in your preferred language

Create lines from points

427
10
3 weeks ago
RITASHKOUL
Regular Contributor

 

Hi,

I am creating a GP tool that will have a input feature layer and also have output feature class path. I have a custom logic which first is converting points layer data into a group of related points and then each group of related points are converted into single line or not.
But there are different types of relationship between these related points. One basic use is to create a straight line from the points. Next one can be there will always be 3 points in that case we need to create an arc. In another use case, points will be created as closed arc and also another one is where a closed square will be created. This will be identified using a custom logic into which related points will fall into.

My first question is can we handle all these cases and different shapes to put into a line/poly line output feature class.
And second question is what is a best way to handle this? Should we iterate through all these related points to create poly lines which will be inserted into some table and then at last will be converted to our mentioned output feature class. Or is there any existing GP tool that can help?

 

What I have done is first I created an empty feature class and then creating lines from related points into the feature class. But I can't seem to find any API to create arc or closed arc using arcpy.

@AlfredBaldenweck  @HaydenWelch @BlakeTerhune @JakeSkinner @Luke_Pinner 

Tags (1)
0 Kudos
10 Replies
BlakeTerhune
MVP Regular Contributor

It looks like the geometry object in arcpy does not support the creation of true curves.

Any true curves in the geometry will be densified into approximate curves in the WKT string.

A possible workaround seems to be to create your feature as GeoJSON and load it in a FeatureSet, then copy the features.

0 Kudos
RITASHKOUL
Regular Contributor

@BlakeTerhune I am iterating and inserting straight line data as well. Can we also update/copy in the same iteration in the same feature class as well for arc and closed arc? I have a dictionary type data of a feature which represents points. Now how to create json out of it and then add curves data and the update the same in my output feature class?

0 Kudos
BlakeTerhune
MVP Regular Contributor

Yes, you can use the same method for creating regular (non-curve) polyline features. As for how to construct your GeoJSON, I don't have experience doing that with curves. I recommend reading the documentation. For practice, you can manually create sample features (with curves) in ArcGIS Pro, then export them to GeoJSON to see how the structure changes for different geometries.

0 Kudos
RITASHKOUL
Regular Contributor

@BlakeTerhune I created an arc and then converted the feature into JSON. By looking into that JSON, I created by own JSON for my arc. It contains start, end and middle points to create an arc. I passed that JSON to arcpy.AsShape. If you will pass the whole feature set then will get record set but if you will pass only geometry then it is failing. As per the documentation, record set contains json representation of the new geometry but I am not getting the same. Not sure I am missing anything.

Input JSON:  data = {
"hasZ":True,
"geometryType":"esriGeometryPolyline",
"spatialReference":{
"wkid":wkid
},
"features":[
{
"geometry":{
"hasZ":True,
"curvePaths":[
[
start,
{
"c":[
end,
center
]
}
]
]
}
}
]
}

data =arcpy.AsShape(esri_json, True)
geo = json.loads(data.JSON)

data.JSON value I am getting

{"displayFieldName":"","hasZ":true,"fieldAliases":{"OID":"OID","Shape_Length":"Shape_Length"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":3008,"latestWkid":3008},"fields":[{"name":"OID","type":"esriFieldTypeOID","alias":"OID"},{"name":"Shape_Length","type":"esriFieldTypeDouble","alias":"Shape_Length"}],"features":[{"attributes":{"OID":0,"Shape_Length":null}}]}

I cant seem to get any new geometry. In its feature set json's, there is no new geometry which represents a single geometry/arc instead of points. Geometry which is being returned is exactly the same which was in the input json.

Any idea??

 

@AlfredBaldenweck  @HaydenWelch @BlakeTerhune @JakeSkinner @Luke_Pinner 

0 Kudos
BlakeTerhune
MVP Regular Contributor

Have you tried loading the JSON into a FeatureSet and copying it to a new feature class like the original solution suggested?

fs = arcpy.FeatureSet()
fs.load(r'C:\path_to_your_json_file.json')
arcpy.management.CopyFeatures(fs, r'C:\some_folder\test_workspace.gdb')
0 Kudos
RITASHKOUL
Regular Contributor

 

@BlakeTerhune 

I didn't try this. But I only want to create shape/geometry and not the whole feature. That's why I was trying to use AsShape instead of FeatureSet. Is there any way to create only arc shape?

0 Kudos
BlakeTerhune
MVP Regular Contributor

Using the Features to JSON gp tool and choosing the "Output to GeoJSON" option creates a file with .geojson extension. I just tested and I got fully completed JSON. Herer's an abbreviated example.

 

{"type":"FeatureCollection","crs":{"type":"name","properties":{"name":"EPSG:3008"}},"features":
    [{
        "type":"Feature","id":1,"geometry":{
            "type":"LineString","coordinates":[
                [235902.8376000002,6695217.4102999996],
                [235915.07869883571,6695060.7613401897],
                ... SNIP ...
                [235928.1163439769,6694904.1766636735],
                [218505.00329999998,6689909.5965]
            ]
        },
        "properties":{
            "OBJECTID":1,
            "Shape_Length":401574.90631927003,
            "MyCustomField":"a value here"
        }
    }]
}

 

 The JSON you posted is all empty. It should have values.

EDIT:

I just noticed that Feature to JSON is simplifying the geometry into straight line segments instead of a curve. Sorry.

0 Kudos
BlakeTerhune
MVP Regular Contributor

If you don't choose the "Output to GeoJSON" option and let it make "Esri JSON", it preserves the true curves. Here's a full example to test with a FeatureSet.

{
  "displayFieldName" : "",
  "fieldAliases" : {
    "OBJECTID" : "OBJECTID",
    "Shape_Length" : "Shape_Length",
    "MyCustomField" : "MyCustomField"
  },
  "geometryType" : "esriGeometryPolyline",
  "spatialReference" : {
    "wkid" : 3008,
    "latestWkid" : 3008
  },
  "fields" : [
    {
      "name" : "OBJECTID",
      "type" : "esriFieldTypeOID",
      "alias" : "OBJECTID"
    },
    {
      "name" : "Shape_Length",
      "type" : "esriFieldTypeDouble",
      "alias" : "Shape_Length"
    },
    {
      "name" : "MyCustomField",
      "type" : "esriFieldTypeString",
      "alias" : "MyCustomField",
      "length" : 255
    }
  ],
  "features" : [{"attributes":{"OBJECTID":2,"Shape_Length":21456.640390208202,"MyCustomField":"my value"},"geometry":{"curvePaths":[[[258018.72869999986,6677229.8190000001],{"c":[[268339.47780000046,6681063.2401000001],[260595.32177711991,6686102.864274309]]}]]}}]
}
0 Kudos
RITASHKOUL
Regular Contributor

 

@BlakeTerhune I am able to create an arc. But now the problem I am seeing is with a closed arc/circle. First question is, I am not sure we can create a closed arc feature in polyline type. And second to create close arc I am using keyword "a". 

e.g.  {
"curvePaths": [
[
[184546.5194, 6339771.4325, 165.7935],
{"a": [[184546.5194, 6339771.4325, 165.7935], [184550.2410, 6339766.7671], 0, 0]}
]
],
"hasZ": True
}) Outside "a" is start point then inside "a" first is again start point and second is center point.

 

Following this structure:

{
"a": [
[<x>, <y>, <z>, <m>],
[<center_x>, <center_y>],
<minor>,
<clockwise>,
<rotation>,
<axis>,
<ratio>
]
} But still seeing some problem. Any idea if I am missing anything in the json.

0 Kudos