Select to view content in your preferred language

How to calculate flooded areas for the shore line

1888
16
11-13-2017 01:36 AM
stashavint
Emerging Contributor

Hello everyone, am trying to calculate the flooded areas of a coastal area, I am using sea level rise and storm surge. The storm surges given are small stretches of the coastal line and I am stuck on how to go about this using arcpy. Below is the table of my storm surge with S10 meaning 10 years and S100 meaning 100 years with each row representing a stretch on the coastal area. 

I tried to clip each row with the input raster data but i am getting errors. 

fc = arcpy.GetParameterAsText(2)
inputraster = arcpy.GetParameterAsText(3)
with arcpy.da.SearchCursor(fc, ["SHAPE@"]) as cursor1:
     for rows in cursor1: 
     geom = rows[0] 
del cursor1
cursor = arcpy.da.SearchCursor(fc,['S10','S100'])
row = cursor.next()
while row:
   while row[0]:
     outputclip = outputfolder + str(row[0])+ "_C"
     clipgeo = geom
     extent = str(clipgeo.Extent)
     arcpy.Clip_management(inputraster,extent,outputclip,"#","ClippingGeometry","MAINTAIN_EXTENT")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Any help is really appreciated. Thanks.

Tags (1)
0 Kudos
16 Replies
DanPatterson_Retired
MVP Emeritus

Code Formatting... the basics++ to format your code so syntax and structure can be checked

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ok... what are the errors. since the first 7 lines of code essentially do nothing and line 5 is indented improperly and even if it wasn't, you delete the cursor1 object so it is gone. and where is getparameterastext numbers 0 and 1?

0 Kudos
stashavint
Emerging Contributor

that was just a part of the code i was writing, the error i get says :

ExecuteError: ERROR 000622: Failed to execute (Clip). Parameters are not valid.
ERROR 000628: Cannot set input into parameter rectangle.
0 Kudos
DanPatterson_Retired
MVP Emeritus

repost a fixed up version of your code.  The error states that one of the parameters is incorrect

http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/clip.htm

and the code in its current state makes it hard to figure out what specifically this is without guessing

0 Kudos
XanderBakker
Esri Esteemed Contributor

I notice that you are clipping a raster and provide a string version of the rectangle. See the code below:

import arcpy
ext = arcpy.Extent(1952602, 294196, 1953546, 296176)
print str(ext)

print " ".join(str(ext).split(" ")[:4])

extent = "{0} {1} {2} {3}".format(ext.XMin, ext.YMin, ext.XMax, ext.YMax)
print extent

The first print statement will give you the extent as you generate it (simply converting the extent object to string), the second what you could do to get a valid syntax of the extent and the third a more readable version.

This will yield:

1952602 294196 1953546 296176 NaN NaN NaN NaN
1952602 294196 1953546 296176
1952602.0 294196.0 1953546.0 296176.0

To be able to see what is going wrong, you should provide the entire code since there are several things missing (parameters 0 and 1, how is the path defined, etc) that could be causing errors. And if it is not the code, it might be data related. So if possible provide the data too.

0 Kudos
stashavint
Emerging Contributor

Thanks for your response, below is the whole code and what is required am trying to calculate flooded area using sea level rise and storm surge. The storm surge is given in form of a polyline of the shore with the different areas of the shore having different storm surges as it can be seen in the table below:

and here is the code:

import arcpy, os,sys
arcpy.env.overwriteOutput = True

sealevel = arcpy.GetParameterAsText(0)
outputfolder = arcpy.GetParameterAsText(1)
fc = arcpy.GetParameterAsText(2)
inputraster = arcpy.GetParameterAsText(3)
floodedarea = arcpy.GetParameterAsText(4)

path = os.path.dirname(os.path.abspath(outputfolder))
outputname = os.path.basename(outputfolder)


#creating output folder
#if arcpy.Exists(outputname):
 #pass
#else:
 #arcpy.CreateFolder_management(path,outputname)
#sr = arcpy.SpatialReference(32145)
#lastempdata = "tmpLayer"

with arcpy.da.SearchCursor(fc, ["SHAPE@"]) as cursor1:
     for rows in cursor1: 
     geom = rows[0] 
del cursor1

cursor = arcpy.da.SearchCursor(fc,['S10','S100'])
row = cursor.next()
while row:
   while row[0]:
   outputclip = outputfolder + str(row[0])+ "_C"
   clipgeo = geom
   #extent = str(clipgeo.Extent)
   arcpy.Clip_management(inputraster,clipgeo,outputclip,"#","ClippingGeometry","MAINTAIN_EXTENT")

'''for i in range(2,7,2):
 arcpy.AddMessage("When i is {0}".format(i))
 rows.reset()
 for row in rows:
 if row[0]:
 new_row = row[0]+i
 floodedraster = arcpy.Raster(inputraster)
 areasbelow = floodedraster <= new_row
 areasbelow.save(floodedarea)'''
 #arcpy.AddMessage(new_row)
 

the coastal line is as shown below:

and the raster data is as shown below:

0 Kudos
XanderBakker
Esri Esteemed Contributor

If you have small stretches of coast line each with different S1, S10 (or any other attribute) values, you may have to extract points from the lines with the attribute value, interpolate those values and then use the raster to calculate those parts underneath the value and set them as potentially flooded. Is that more or less what you want to achieve?

0 Kudos
stashavint
Emerging Contributor

Yes thats what am trying to achieve, for example each row represent a certain area of the coast, eg row 0 is a stretch with its storm surge, so i want the flooded area from that stretch and goes on. So at the end you have the flooded coastal but from each line which represents just part of the coast.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Do you mind sharing (part of) the featureclass with the coastal segments and S1, S10, etc attributes. I want to investigate something, but my first impression is that if there are connecting segments with different S1, S10 S100 values, there will be unnatural breaks between them. I wonder if extracting points a certain way and interpolations will reduce that effect. How was the value determined for each segment? Does it really apply to the entire segment or does it represent for instance the center value of the segment?

0 Kudos