AnsweredAssumed Answered

PolygonToRaster in stand alone script

Question asked by Lconner_macon on Jul 7, 2017
Latest reply on Jul 8, 2017 by curtvprice

my code is:

 

print "running..."
import arcpy
import arcpy, os
from arcpy import env
import os
import os.path
env.workspace =r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\route_polygons.mxd"


global shp
shp = ".shp"

global tif
shp = ".tif"


x=1

in_features= r'P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\meters.shp'
out_layer = 'meters_temp'
arcpy.MakeFeatureLayer_management (in_features, out_layer,)

in_features2= r'P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\parcels.shp'
parcles_temp = 'parcles_temp'
arcpy.MakeFeatureLayer_management (in_features2, parcles_temp,)

while x <= 2:
    import arcpy
    import arcpy, os
    from arcpy import env
    import os
    import os.path

    # slection fuction: select meters with x for cycle/ route
    layer = out_layer
    criteria = 'route_sequ =' + str(x)
    arcpy.SelectLayerByAttribute_management (layer,'NEW_SELECTION',criteria)
   
    #slect by location: select parcles by selected meters
    in_layer = parcles_temp
    selector = out_layer
    distance = 60
    arcpy.SelectLayerByLocation_management (in_layer,select_features = selector, search_distance=distance )

    #copy features to shape file
    in_features = parcles_temp
    out_feature_class = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\" + str(x) + shp
    arcpy.CopyFeatures_management(in_features, out_feature_class)

    #merge polpgons in to 1
    in_features = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\" + str(x) + shp
    out_feature_class = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\" + str(x)+'merge' + shp
    arcpy.Dissolve_management (in_features, out_feature_class, multi_part='MULTI_PART')

    # add feild
    in_table = out_feature_class
    field_name = "Route"
    field_type = 'TEXT'
    arcpy.AddField_management (in_table, field_name, field_type, field_length=10)

    #populate feild
    in_table =out_feature_class
    field= "Route"
    expression = x
    arcpy.CalculateField_management (in_table, field, expression)

    #add cycle feild
    in_table = out_feature_class
    field_name = "Cycle"
    field_type = 'TEXT'
    arcpy.AddField_management (in_table, field_name, field_type, field_length=10)

    #apend in to database
    inputs = out_feature_class
    target = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\route_polygons.shp"
    arcpy.Append_management (inputs, target, schema_type='NO_TEST')

    # expoert to raster
    in_features =r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\" + str(x)+'merge' + shp
    value_field = "Route"
    out_rasterdataset = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\TIFF" + str(x) + ".tif"
    arcpy.PolygonToRaster_conversion (in_features, value_field, out_rasterdataset)

    print x
    x=x+1
print "done"

 

everything works except for the last function PolygonToRaster. the error i get is:

Traceback (most recent call last):
  File "P:\GIS Public\Projects\Meter Zones\route_polygons\make_route_pologons.py", line 53, in <module>
    arcpy.Dissolve_management (in_features, out_feature_class, multi_part='MULTI_PART')
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 4192, in Dissolve
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\1.tif does not exist or is not supported
Failed to execute (Dissolve).

 

i need to export the files in to a TIFF file. i know  something wrong with the line out_rasterdataset = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\TIFF" + str(x) + ".tif". can you help with the syntax?

 

thank you

Outcomes