field mapping issue in addlocations method

630
3
11-03-2016 06:45 AM
clementinechasles
New Contributor

Hello everyone,

Do you know how to map a field in the Arcpy's AddLocations method, from a GPFeatureRecordSetLayer dataset (FeatureSet from my JavaScript code) ?

I created an OD matrix that runs well and that's got for inputs destination GPFeatureRecordSetLayer. It seems to be a problem in the field mapping when I add a location to my destinations, since my location to add are GPFeatureRecordSetLayer and not a Table View. The field mapping goes well when I try it with a table but not with my FeatureSet. Therefore, in output, I don't have the names of my destinations as I wanted to have with the field mapping, but a default name (Location 1, or 2, or 3 ...). Difficult to retrieve the good destination then !

I wish I was enough clear. I can forward my piece of code if you need.

Thanks in advance !

0 Kudos
3 Replies
LukeWebb
Occasional Contributor III

Please provide us with your script to maybe help us out a bit more, are the fields named the same in the Feautreset as the Table you tested with?

Could you do:

featureset = arcpy.FeatureSet()

featureset .load(input_data)

featureset .save(temporary_table.shp)

tool_run(temporary_table.shp)

0 Kudos
clementinechasles
New Contributor

Thanks Luke,

Here's my code :

# Import arcpy module
import sys, os, arcpy

path = "path_BASE_ROUTIERE"
matrix = "matrix"
SIG = "SDEconnection"
query = arcpy.GetParameterAsText(0)
destination = arcpy.GetParameterAsText(1)

# Process: Make OD Cost Matrix Layer
arcpy.MakeODCostMatrixLayer_na(path, matrix, "NETWORK", "", "", "", "ALLOW_UTURNS", "Oneway", "USE_HIERARCHY", "", "NO_LINES", "")
arcpy.MakeQueryLayer_management(SIG,"QUERY", query, "INSEE", "POINT", "2154","")

# Process: Add Origins
arcpy.AddLocations_na(matrix, "Origins", "QUERY", "CurbApproach CurbApproach 0;Name INSEE #;SourceID SourceID #;SourceOID SourceOID #;PosAlong PosAlong #;SideOfEdge SideOfEdge #", "5000 Meters", "", "L93_BDROUTE SHAPE;BDROUTE_12_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "L93_BDROUTE #;BDROUTE_12_Junctions #")

# Process: Add Destinations
arcpy.AddLocations_na(matrix, "Destinations", destination, "Name Name #", "5000 Meters", "", "L93_BDROUTE SHAPE;BDROUTE_12_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "L93_BDROUTE #;BDROUTE_12_Junctions #")

# Process: Solve
arcpy.Solve_na(matrix, "SKIP", "TERMINATE", "")

The destinations/featureset in JSON format are passed in the local variable "destination" from my JavaScript code. This piece of code is in fact a part of a webservice called in REST.

The result is then pushed in an oracle database on a server.

0 Kudos
clementinechasles
New Contributor

And my input destination :

{    
    "geometryType":"esriGeometryPoint",
    "features":[{
                    "geometry":{
                                         "x":482548.57666716713,
                                         "y":6509457.736269861,
                                         "spatialReference":{
                                                                         "wkid":102110,
                                                                         "latestWkid":2154
                                                                         }
                                      },
                    "attributes":{
                                    "Name":"Name",
                                    "CODE_ETA":"test",
                                    "DATE_ALIM":"7 nov. 2016",
                                    "REGCODE":null,
                                    "REGNOM":null,
                                    "X":482548.57666716713,
                                    "Y":6509457.736269861,
                                }
                }],
    "sr":{
            "wkid":102110,
            "latestWkid":2154
        }
}

0 Kudos