POST
|
Thank you! I am trying to use your suggestion for another code. The purpose is to determine the frontage of parcels along a road system. I have created a buffer to use in select by location. I want to select all lines that completely fall within the buffer and then calculate the sum of lines that correspond to each parcel and then populate a field called "Frontage". I have used most of the code from this thread to try and accomplish the frontage calculation. I dont think I put the TabulateIntersection_analysis in the correct place and I am not sure that everything from line 72 down is necessary. Any suggestions? # Import the Arcpy Module
import arcinfo
import arcpy
from arcpy import env
# Set up the working Environment
env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True
#Variables
Parcels = "R40_80000sqft"
Street_Center = "ROAD_CL_2017_12"
arcpy.MakeFeatureLayer_management(Parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Street_Center,"Street_Lyr")
Street_Lyr = "Street_Lyr"
Parcels_lyr = "Parcels_Lyr"
#Add a field to parcels to be populated with building area
arcpy.AddField_management(Parcels,"Frontage","DOUBLE")
# Buffer Street Center Lines
arcpy.Buffer_analysis(Street_Lyr,"Street_Buff","40 Feet","FULL","ROUND","ALL")
Street_Buff = "Street_Buff"
#Convert parcel layer polygons to lines
arcpy.PolygonToLine_management(Parcels_lyr,"R40_PolyToLine")
R40_Line = "R40_PolyToLine"
###Convert parcel lines to a layer for use in select by location
##arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr")
##
##R40_Line_Lyr = "R40_Line_Lyr"
#Create a cursor to select all parcel lines that fall within the street buffer
with arcpy.da.UpdateCursor(Parcels_lyr, ['Shape@','Frontage','OID@']) as linecursor:
for linerow in linecursor:
#get the geometry to use in the spatial selection
geom = linerow[0]
oid = str(linerow[2])
R40_Line = "R40_PolyToLine"
arcpy.TabulateIntersection_analysis(R40_Line, "OBJECTID", Parcels_lyr, r"in_memory\TabIntSum")
#Convert parcel lines to a layer for use in a select by location
arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr","LEFT_FID = " + oid)
arcpy.JoinField_management(r"in_memory\TabIntSum","OBJECTID_1",Parcels_lyr,"OBJECTID")
#select parcel lines from the street buffer using the geom variable
arcpy.SelectLayerByLocation_management("R40_Line_Lyr", "COMPLETELY_WITHIN", Street_Buff, "", "NEW_SELECTION")
#get the Length of the selected features and sum
lengthsum = 0
with arcpy.da.SearchCursor("R40_Line_Lyr",['SHAPE@LENGTH']) as newcursor:
for newrow in newcursor:
lengthsum = lengthsum + newrow[0]
print lengthsum
del newcursor
parcelrow[1]= lengthsum
if lengthsum != 0:
parcelrow[2] = lengthsum
else:
parcelrow[2] = 0
linecursor.updateRow(linerow)
del linecursor
... View more
12-08-2017
08:38 AM
|
0
|
0
|
868
|
POST
|
My current code is 0's for length sum in line 71. Is this happening because the indentation of the if statement is wrong(Line 77)? I also turned off the Make Feature Layer in line 46 since I am making a feature layer in line 60 now. # Import the Arcpy Module
import arcinfo
import arcpy
from arcpy import env
# Set up the working Environment
env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True
#Variables
Parcels = "R40_80000sqft"
Street_Center = "ROAD_CL_2017_12"
arcpy.MakeFeatureLayer_management(Parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Street_Center,"Street_Lyr")
Street_Lyr = "Street_Lyr"
Parcels_lyr = "Parcels_Lyr"
#Add a field to parcels to be populated with building area
arcpy.AddField_management(Parcels,"Frontage","DOUBLE")
# Buffer Street Center Lines
arcpy.Buffer_analysis(Street_Lyr,"Street_Buff","40 Feet","FULL","ROUND","ALL")
Street_Buff = "Street_Buff"
#Convert parcel layer polygons to lines
arcpy.PolygonToLine_management(Parcels_lyr,"R40_PolyToLine")
R40_Line = "R40_PolyToLine"
###Convert parcel lines to a layer for use in select by location
##arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr")
##
##R40_Line_Lyr = "R40_Line_Lyr"
#Create a cursor to select all parcel lines that fall within the street buffer
with arcpy.da.UpdateCursor(Parcels_lyr, ['Shape@','Frontage','OID@']) as linecursor:
for linerow in linecursor:
#get the geometry to use in the spatial selection
geom = linerow[0]
oid = str(linerow[2])
R40_Line = "R40_PolyToLine"
#Convert parcel lines to a layer for use in a select by location
arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr","LEFT_FID = " + oid)
#select parcel lines from the street buffer using the geom variable
arcpy.SelectLayerByLocation_management("R40_Line_Lyr", "COMPLETELY_WITHIN", Street_Buff, "", "NEW_SELECTION")
#get the Length of the selected features and sum
lengthsum = 0
with arcpy.da.SearchCursor("R40_Line_Lyr",['SHAPE@LENGTH']) as newcursor:
for newrow in newcursor:
lengthsum = lengthsum + newrow[0]
print lengthsum
del newcursor
parcelrow[1]= lengthsum
if lengthsum != 0:
parcelrow[2] = lengthsum
else:
parcelrow[2] = 0
linecursor.updateRow(linerow)
del linecursor
... View more
12-08-2017
06:58 AM
|
0
|
1
|
902
|
POST
|
I currently have a code that is performing most of what i want it to do but I need to associate summed values with the corresponding parcels. Right now I believe the code is giving me the sum of all frontage that falls within a buffer area. I need to figure out how to sum each of the lines that make up individual parcels, sum them and add them to a field in the parcel layer. # Import the Arcpy Module
import arcinfo
import arcpy
from arcpy import env
# Set up the working Environment
env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True
#Variables
Parcels = "R40_80000sqft"
Street_Center = "ROAD_CL_2017_12"
arcpy.MakeFeatureLayer_management(Parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Street_Center,"Street_Lyr")
Street_Lyr = "Street_Lyr"
Parcels_lyr = "Parcels_Lyr"
#Add a field to parcels to be populated with building area
arcpy.AddField_management(Parcels,"Frontage","DOUBLE")
# Buffer Street Center Lines
arcpy.Buffer_analysis(Street_Lyr,"Street_Buff","40 Feet","FULL","ROUND","ALL")
Street_Buff = "Street_Buff"
#Convert parcel layer polygons to lines
arcpy.PolygonToLine_management(Parcels_lyr,"R40_PolyToLine")
R40_Line = "R40_PolyToLine"
#Convert parcel lines to a layer for use in select by location
arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr")
R40_Line_Lyr = "R40_Line_Lyr"
#Create a cursor to select all parcel lines that fall within the street buffer
with arcpy.da.UpdateCursor(Parcels_lyr, ['Shape@','Frontage']) as linecursor:
for linerow in linecursor:
#get the geometry to use in the spatial selection
geom = linerow[0]
#select parcel lines from the street buffer using the geom variable
arcpy.SelectLayerByLocation_management(R40_Line_Lyr, "COMPLETELY_WITHIN", Street_Buff, "", "NEW_SELECTION")
#get the Length of the selected features and sum
lengthsum = 0
with arcpy.da.SearchCursor(R40_Line_Lyr,['SHAPE@LENGTH']) as newcursor:
for newrow in newcursor:
lengthsum = lengthsum + newrow[0]
print lengthsum
del newcursor
parcelrow[1]= lengthsum
if lengthsum != 0:
parcelrow[2] = lengthsum
else:
parcelrow[2] = 0
linecursor.updateRow(linerow)
del linecursor
... View more
12-07-2017
09:15 AM
|
0
|
3
|
1248
|
POST
|
I realized I have another problem. I need it to use the other attribute to determine which parcel the line segments belong to otherwise it will just sum every line segment that falls within the buffer area.
... View more
12-07-2017
08:55 AM
|
0
|
0
|
868
|
POST
|
Thank you! The Script is working exactly as I had hoped. I am now trying to apply the same script to figuring out frontage. I want the script to select the lines I created from the parcels that fall within the buffer of the road, sum the total length of frontage lines and out put the sum to the frontage field. The script runs but nothing is put into the frontage field. Any suggestions? # Import the Arcpy Module
import arcinfo
import arcpy
from arcpy import env
# Set up the working Environment
env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True
#Variables
Parcels = "R40_80000sqft"
Street_Center = "ROAD_CL_2017_12"
arcpy.MakeFeatureLayer_management(Parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Street_Center,"Street_Lyr")
Street_Lyr = "Street_Lyr"
Parcels_lyr = "Parcels_Lyr"
#Add a field to parcels to be populated with building area
arcpy.AddField_management(Parcels,"Frontage","DOUBLE")
arcpy.Buffer_analysis(Street_Lyr,"Street_Buff","40 Feet","FULL","ROUND","ALL")
Street_Buff = "Street_Buff"
arcpy.PolygonToLine_management(Parcels_lyr,"R40_PolyToLine")
R40_Line = "R40_PolyToLine"
arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr")
R40_Line_Lyr = "R40_Line_Lyr"
#Create a cursor to select all parcel lines that fall within the street buffer
with arcpy.da.UpdateCursor(Parcels_lyr, ['Shape@','Frontage']) as linecursor:
for linerow in linecursor:
#get the geometry to use in the spatial selection
geom = linerow[0]
#select feature from the other layer using the geom variable
arcpy.SelectLayerByLocation_management(R40_Line_Lyr, "COMPLETELY_WITHIN", Street_Buff, "", "NEW_SELECTION")
#get the Length of the selected features and sum
lengthsum = 0
with arcpy.da.SearchCursor(Street_Lyr,['SHAPE@LENGTH']) as newcursor:
for newrow in newcursor:
lengthsum = lengthsum + newrow[0]
print lengthsum
del newcursor
parcelrow[1]= lengthsum
if areasum != 0:
parcelrow[2] = geom.length / lengthsum
else:
parcelrow[2] = 0
linecursor.updateRow(linerow)
del linecursor
... View more
12-07-2017
08:53 AM
|
0
|
1
|
868
|
POST
|
Thank you for the additional help. I added the field to the table that you selected and added the additional code. I am getting an error at line 60. Any idea why I would be getting the error? # Import the Arcpy Module
import arcinfo
import arcpy
from arcpy import env
# Set up the working Environment
env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True
#Variables
Parcels ="R40_80000sqft"
Structures = "Nantucket_Structres"
arcpy.MakeFeatureLayer_management(parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Structures,"Struc_Lyr")
Struc_Lyr = "Struc_Lyr"
Parc_Lyr = "Parcels_Lyr"
#Add a field to parcels to be populated with building area
arcpy.AddField_management(Parcels,"Bldg_Area","DOUBLE")
arcpy.AddField_management(Parcels,"Free_Area","DOUBLE")
with arcpy.da.UpdateCursor(Parc_Lyr, ['Shape@']) as parcelcursor:
for parcelrow in parcelcursor:
#get the geometry to use in the spatial selection
geom = parcelrow[0]
#select feature from the other layer using the geom variable
arcpy.SelectLayerByLocation_management(Struc_Lyr, "HAVE_THEIR_CENTER_IN", geom, "", "NEW_SELECTION")
#get the area of the selected features and sum
areasum = 0
with arcpy.da.SearchCursor(Struc_Lyr,['Shape@AREA']) as newcursor:
for newrow in newcursor:
areasum = areasum + newrow[0]
print areasum
del newcursor
parcelrow[1]= areasum
if areasum != 0:
parcelrow[2] = geom.area / areasum
else:
parcelrow[2] = 0
parcelcursor.updateRow(parcelrow)
del parcelcursor
... View more
12-07-2017
06:59 AM
|
0
|
3
|
868
|
POST
|
I tried adding an update cursor to the end of the code to add the areasum to the "Bldg_Area" field of the parcel layer. It didn't work. Import the Arcpy Module import arcinfo import arcpy from arcpy import env Set up the working Environment env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb" env.overwriteOutput = True #Variables Parcels ="R40_80000sqft" Structures = "Nantucket_Structres" arcpy.MakeFeatureLayer_management(parcels,"Parcels_lyr") arcpy.MakeFeatureLayer_management(Structures,"Struc_Lyr") Struc_Lyr = "Struc_Lyr" Parc_Lyr = "Parcels_Lyr" #Add a field to parcels to be populated with building area arcpy.AddField_management("R40_80000sqft","Bldg_Area","DOUBLE") with arcpy.da.SearchCursor(Parc_Lyr, ) as parcelcursor: for parcelrow in parcelcursor: #get the geometry to use in the spatial selection geom = parcelrow[0] #select feature from the other layer using the geom variable arcpy.SelectLayerByLocation_management(Struc_Lyr, "HAVE_THEIR_CENTER_IN", geom, "", "NEW_SELECTION") #get the area of the selected features and sum areasum = 0 with arcpy.da.SearchCursor(Struc_Lyr,['Shape@AREA']) as newcursor: for newrow in newcursor: areasum = areasum + newrow[0] print areasum with arcpy.da.UpdateCursor(Parcels, ) as parcelcursor: for parcelrow in parcelcursor: row[0]=areasum
... View more
12-06-2017
01:55 PM
|
0
|
6
|
868
|
POST
|
It worked!!! Now I need to add those values to their corresponding parcel. Would I use and input cursor of some kind for that?
... View more
12-06-2017
12:32 PM
|
0
|
0
|
868
|
POST
|
I am not sure how you are getting the to paste in correctly. When I paste it in this is how it ends up. The code is running now. The only issue is that it doesn't seem to be giving me the sum of all buildings together in each parcel. It is giving me the area of each individual building. # Set the necessary product code # import arcinfo # Import the Arcpy Module import arcpy from arcpy import env # Set up the working Environment env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb" env.overwriteOutput = True #Variables Parcels ="R40_80000sqft" Structures = "Nantucket_Structres" arcpy.MakeFeatureLayer_management(parcels,"Parcels_lyr") arcpy.MakeFeatureLayer_management(Structures,"Struc_Lyr") Struc_Lyr = "Struc_Lyr" Parc_Lyr = "Parcels_Lyr" #Add a field to parcels to be populated with building area #arcpy.AddField_management("R40_80000sqft","Bldg_Area","DOUBLE") with arcpy.da.SearchCursor(Parc_Lyr, ['Shape@']) as parcelcursor: for parcelrow in parcelcursor: #get the geometry to use in the spatial selection geom = parcelrow[0] #select feature from the other layer using the geom variable arcpy.SelectLayerByLocation_management(Struc_Lyr, "HAVE_THEIR_CENTER_IN", geom, "", "NEW_SELECTION") #get the area of the selected features and sum areasum = 0 with arcpy.da.SearchCursor(Struc_Lyr,['Shape@AREA']) as newcursor: for newrow in newcursor: areasum = areasum + newrow[0] print areasum
... View more
12-06-2017
12:06 PM
|
0
|
9
|
2009
|
POST
|
I am hitting a snag at line 50. I am getting an error stating totarea is not defined. should line 47 be totarea instead of areasum?
... View more
12-06-2017
10:47 AM
|
0
|
11
|
2009
|
POST
|
This is what I have so far. It still is not working though. Something is wring with the search cursor at line 31. in your line 1 you have input_fc. Should this be the parcel feature class? you then have parcel_feature class stated after the field to be used. Why?
... View more
12-06-2017
10:18 AM
|
0
|
13
|
2009
|
POST
|
This is awesome, thank you! Would the Summary Statistics (3) and the summary stats output (4) be inside of step 2's for loop?
... View more
12-06-2017
09:45 AM
|
0
|
0
|
2009
|
POST
|
I am trying to use cursor and for loop to select each row of a feature class, then select features from another feature class using select by location and the selection from the former feature class. Then add up the shape areas of the selection and out put them into a field in the first feature class. 1. Step through each row of a feature class selecting them one at a time (Parcels) -I tried using a cursor for this step 2. perform a select by location using the selection from the first step and another feature class (Buildings) -I cannot figure out how to get the row to be used in the select by location 3. Sum the "shape area" of the selection from step 2 - I don't know the command to perform this step 4. Output the sum into a field in the first feature class (Parcels) - I don't know the command to perform this step 5. divide the shape area of Buildings by the Parcel shape area to get a % of development - I believe I can write this command but I have not been able to get this far in the code I have not been able to find a similar python process on stack exchange. I have made several attempts at writing the code in what I feel like is a logical order but have not had any luck. Does anyone possibly have a similar code or can anyone provide me with a list of python processes to use? Thank you
... View more
12-06-2017
07:12 AM
|
0
|
19
|
4966
|
POST
|
I have an image over Nantucket which covers the downtown area of the Island. The image is from 1957. I would like to get imagery from the same year covering the entire Island. The name of the company was Aerial Surveys Inc based out of Boston MA. Has anyone heard of the company or know where I might be able to find Imagery from 1957 covering the entire island?
... View more
08-07-2017
10:48 AM
|
1
|
1
|
575
|
Title | Kudos | Posted |
---|---|---|
1 | 08-07-2017 10:48 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|