AnsweredAssumed Answered

ArcGIS Server: incorrect return values of a feature to calculate the extent

Question asked by SandSloper3 on Dec 6, 2017

I start to develop a script to run it on the ArcGIS-Server but hang at the beginning by calculatining the extent of a created Shapefile from a input JSON file. Here I copy all the parsed points into a Shapefile from which i like to get the extent for further calculation steps. If I run my script inside the desktop environment everything works fine but after i published my script on the serverside, the issue is wrong.

Can someone tell me where the mistake is ? I tried everything but was not able to fix ist. The Server and desktopversion is 10.5.1 Here is my little Code:

class Toolbox:

    def execute(self,xy_json,indicator,time,epsg):

        sr = arcpy.SpatialReference()
        sr.factoryCode = epsg
        sr.create()

        # ENV Settings
        arcpy.env.overwriteOutput = 1
        arcpy.env.outputCoordinateSystem = sr

        json_obj = []

        tif = os.path.join(arcpy.env.scratchFolder,'temp.tif')

        # temp file
        temp_shapefile = os.path.join(arcpy.env.scratchFolder, 'temp_shp')

        # the array which stors the values
        pt_geoms = []
        id_pt_array = []

        inputjson = json.loads(xy_json)

        # json string to shapefile
        pt = arcpy.Point()

        for row in inputjson:
            id = row['id']
            pt.X = row['x']
            pt.Y = row['y']
            id_pt_array.append({'id': id, 'x': round(pt.X, 0), 'y': round(pt.Y, 0)})
            pt_geoms.append(arcpy.PointGeometry(pt))

        pt_geometry = arcpy.CopyFeatures_management(pt_geoms, temp_shapefile)

        arcpy.DefineProjection_management(pt_geometry,sr.exportToString())

        # Process: Minimum Bounding Geometry
        ext = arcpy.Describe(pt_geometry)
        xmin = ext.extent.XMin
        xmax = ext.extent.XMax
        ymin = ext.extent.YMin
        ymax = ext.extent.YMax

        out = '{0},{1},{2},{3}'.format(xmin, ymin, xmax, ymax)

        arcpy.AddMessage('{0}'.format(out))

        arcpy.SetParameterAsText(4, out)


def main():

    #user defined values
    xy_json = arcpy.GetParameterAsText(0)
    indicator = arcpy.GetParameterAsText(1)
    time = arcpy.GetParameterAsText(2)
    epsg = arcpy.GetParameterAsText(3)

    tb = Toolbox()
    tb.execute(xy_json,indicator,time,epsg)

if __name__ == '__main__': main()

The correct output on the desktopversion with epsg:3035 is: 4339060.59912, 2763757.46692, 4342628.09351, 2766830.13068

but the script on the server brings as output: 4.33953566875e+13, 276579545.0, 4.34262809349e+14, 2.76683013062e+14

I don't want to do a conversation with the result, because the spatial reference must be flexible by user input.

Thanks for Help !

Outcomes