Select to view content in your preferred language

How to create an Shapefile on ArcGIS Server side?

1349
6
11-26-2012 05:17 AM
SvenHarpering
Emerging Contributor
Hi all,

I am developing a script which gets an JSON array with point coordinates. This array is encoded to a python dictionary. From this I filter all points (latitude and longitude) and an ID. This coordinates are converted into arcpy-points by using arcpy.Point(). Now in a next step I want to create a shapefile of these points by using
arcpy.CopyFeatures_management(ptList, r"pointTemp.shp")
.

My question is how to store this shapefile into a folder which is located on ArcGIS Server side. Do I have to give the skript a special path or location?

One folder that is on ArcGIS Server side in my case is "C:\temp", I have full read and wright rights, but the script doesn´t create the shapefile in this folder. If I run the script local on my pc, all works fine and the shape is created and stored locally on "C:\temp".

Any suggestions or tips?

Thanks!
Sven
Tags (2)
0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Sven,

In your script specify the Temp drive using a UNC path.  Ex:

\\<ArcGIS Server name\Temp

Note:  be sure the Temp drive is shared

Another option is to publish your script to ArcGIS Server.  The output shapefile will then be written to you 'arcgisjobs' folder on your ArcGIS Server machine.
0 Kudos
SvenHarpering
Emerging Contributor
Thanks, that works! I have a follow-up question. When I want to use the function spatial join, I use as input my point.shp, but how do I have to call a second shape that lies somewhere else on the Server? Sorry, if these are stupid question, but I am new to this stuff.

A Database with FeatureClasses is located here on the Server: C:\arcgisserver\directories\arcgissystem\arcgisinput\project\project.MapServer\extracted\v101\database.gdb

But this path does not work. Do I have to change something? I call the path with r":\arcgisserver\directories\arcgissystem\arcgisinput\project\project.MapServer\extracted\v101\database.gdb\featureClass"

Thanks.

Sven
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Can you post the code that you're using?  Also, what is the error you are receiving?
0 Kudos
SvenHarpering
Emerging Contributor
This is the code I am using:

# -*- coding: cp1252 -*-

# Import modules
import arcpy, arcgisscripting, json

try:
    #Workspace
    #arcpy.env.workspace = r"C:\temp\\"
    gp = arcgisscripting.create()

    # ENV Settings
    arcpy.env.overwriteOutput = 1

    # Local variables
    i = 0 
    value = 0
    ptList = []
    rowNumberList = []
    pt = arcpy.Point()

    #String input:   
    input = arcpy.GetParameterAsText(0)
 
 #JSON array to Python dictionary
    data  = json.loads(input)

    for entries in data['points']:
        rowNumberList.append(data['points']['rowNumber'])
 pt.X = data['points']['longitude']
 pt.Y = data['points']['latitude']
 ptList.append(arcpy.PointGeometry(pt))
 i += 1
 
    # Create the Shape
    arcpy.CopyFeatures_management(ptList, r"pointTemp.shp")

    # Add the filed 'rowNumber'
    arcpy.AddField_management(r"pointTemp.shp", "rowNumber", "SHORT")

    # Fill the field 'rowNumber'
    cur = gp.UpdateCursor(r"pointTemp.shp")
    row = cur.Next()

    while row:
        row.rowNumber = rowNumberList[value]
 cur.UpdateRow(row)
 row = cur.Next()
 value += 1

    del cur

    # Spatial Join
    arcpy.SpatialJoin_analysis(r"pointTemp.shp",r"C:\arcgisserver\directories\arcgissystem\arcgisinput\cresta\lowres_deutschland.MapServer\extracted\v101\cresta.gdb\Cresta_Low_Res",r"join_result.shp")

    # FeatureClass / Shapefile,
    fc = r"join_result.shp"

    # Fields that should be returned by the cursor
    field = ["CRESTA_ID"]

    # Loop through the attribute table with a cursor
    with arcpy.da.SearchCursor(fc, field) as cursor:         
        for row in cursor:
            print str(row[0])       

    arcpy.SetParameterAsText(1, "Eintrag: " + str(row[0]))
            
except Exception, e:
    arcpy.SetParameterAsText(2, e)


My problem is in the spatial join function. Here I need to tell the script where he has to search for the second shape/feature class to join with the point shape.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
What is the error you receive when you execute this code?
0 Kudos
SvenHarpering
Emerging Contributor
Sorry for the late answer. I solved the problem. I didn´t register the UNC path in a correct way.

Thanks for your help.
0 Kudos