|
POST
|
Hi Mary, It sounds to me that the DEM may be a rather flat area and perhaps the DEM is an Integer (rounding all values). If this is the case, only when the DEM "jumps" to the next value a slope will be detected. Did you use a "Z factor"? Is it possible to post a small part of a DEM you have to see if I can detect the problem? Kind regards, Xander
... View more
01-02-2014
05:30 AM
|
0
|
0
|
2076
|
|
POST
|
Hi Palermo, There are several ways of doing this. For instance by following these manual steps: Make sure the point layer has X and Y as fields added to the attribute table. If you don't have them use the "Add XY Coordinates (Data Management)" tool Next use the "Spatial Join (Analysis)" tool to obtain the ID (Feature ID or any other unique ID) of the polygons for each point. Open the attribute table to the points with the joined polygons. Now do a summarize on the field that contains the polygon ID. (see more explanation in the Help topic on "Summarizing data in a table") In this summarize you will calculate the average of the POINT_X and POINT_Y fields. The output is a table that holds the field you summarize on (ID of the polygons) and the average X and Y per polygon. These are the center point coordinates based on the points per polygon. The make this spatial, use the "Make XY Event Layer (Data Management)" tool. Kind regards, Xander
... View more
01-02-2014
05:19 AM
|
0
|
0
|
2277
|
|
POST
|
Hi Phil, The string.isdigit() can be used to test if it is numeric. Looping through the split list (from back) will result in the first number. lstRoads = ['US Hwy 1', 'State Hwy 33 W','State Hwy 29 Bus', 'some 1 other string text with a number','yet another test with a 6 number']
for r in lstRoads:
lstr = r.split(' ')
for i in range(len(lstr)-1,-1,-1):
if lstr.isdigit():
print " - part {0} - in string '{1}' is '{2}' and this is numeric {3}".format(i,r,lstr,float(lstr))
break returns: - part 2 - in string 'US Hwy 1' is '1' and this is numeric 1.0 - part 2 - in string 'State Hwy 33 W' is '33' and this is numeric 33.0 - part 2 - in string 'State Hwy 29 Bus' is '29' and this is numeric 29.0 - part 1 - in string 'some 1 other string text with a number' is '1' and this is numeric 1.0 - part 5 - in string 'yet another test with a 6 number' is '6' and this is numeric 6.0 Please note that if a part contains a number and a character this will not be seen as numeric... Kind regards, Xander
... View more
12-23-2013
01:15 AM
|
0
|
0
|
6381
|
|
POST
|
Hi Matt, Sorry for the delay, but I think the expression is OK, if you change the import statement from: import arcpy,os,arcpy.sa to: import arcpy,os
from arcpy.sa import * This way the Exp function should be recognized. The alternative could be changing the line to: result = arcpy.sa.Exp(inRas * value_from_row) Kind regards, Xander
... View more
12-09-2013
09:44 PM
|
0
|
0
|
1088
|
|
POST
|
Hi Mark, Personally I don't like models, but if you are willing to export the model to a Python script (Model\Export\To Python script) and post this using the "#" button to wrap "CODE" tags arround the code, I can have a look what may be going wrong. And when you say that the last year produces a negative number, this may have to do with Null values. For that I would need to see (part of) the data. Kind regards, Xander
... View more
12-06-2013
03:34 AM
|
0
|
0
|
2322
|
|
POST
|
Hi Matt, I have seen issues with Esri grids that have a name starting with a number. Could you add a character at the beginning of the name (like: "R200905_001")? I also see that the fields are named "Name", "AP" and "Q" when in the code you provided you address them as "A", "B" and "C". A, B and C and used in Excel but aren't the field names in ArcMap. Open the table in ArcMap and see what they are called. Change: fldName1 = 'A'
fldName2 = 'B'
fldName3 = 'C' To: fldName1 = 'Name'
fldName2 = 'AP'
fldName3 = 'Q' If that doesn't work run the code below and post the text that is printed to the thread (it prints out a few rows of your data and what input and output will be used). import arcpy,os
inWS = r'C:\A\B\C\EucDistRasters' # input rasters are stored here
outWS = r'C:\A\B\Test' # output rasters will be stored here
tbl = 'LOOKUP$'
fldName1 = 'Name' # field with output raster name (no path included)
fldName2 = 'AP' # field with input raster name (no path included)
fldName3 = 'Q' # multiply value field
fields = [fldName1,fldName2,fldName3]
cnt=0
with arcpy.da.SearchCursor(tbl, fields) as cursor:
for row in cursor:
cnt+=1
value_from_row = row[2]
inName = row[1]
outName = row[0]
inRasLoc = os.path.join(inWS,inName)
outRasLoc = os.path.join(outWS,outName)
print "Name={0}\tAP={1}\tQ={2}\t".format(outName,inName,value_from_row)
print " - inRasLoc ={0}".format(inRasLoc)
print " - outRasLoc={0}".format(outRasLoc)
if cnt > 5:
break
del row, tbl Kind regards, Xander
... View more
12-05-2013
11:33 PM
|
0
|
0
|
1088
|
|
POST
|
Hi Martin, I'm glad I could be of any assistance. If you think it was helpful you can use the "arrow" button in order to help other members find useful information: More info here: http://resources.arcgis.com/en/help/forums-mvp/ Kind regards, Xander
... View more
12-05-2013
08:37 PM
|
0
|
0
|
1340
|
|
POST
|
Hi Matt, There is another line in your code that will create errors: outWS = r'C:\A\B\Test\' The folder should not end with a slash. It should be like this: outWS = r'C:\A\B\Test' When writing to a folder the format will be an Esri grid (raster). This format has some limitations in naming. The most important are: The maximum number of characters is 13. It cannot have spaces. It cannot use special characters other than underscore ( "_" ). The total length of the name for a Grid and its path cannot be more than 128 characters. You can read more about this in the Help topic on "Output raster formats and names" Could you attach a screen shot of the Excel file you're using? I would like to see what output names are assigned. Kind regards, Xander
... View more
12-05-2013
08:33 PM
|
0
|
0
|
1088
|
|
POST
|
Hi Matt, When you define a path in a Python script there are 3 ways to do this (maybe more, but these are the most common ones):
# use "r" before path
myFGDB = r"C:\A\B\Test\TIMESLOOKUP.gdb"
# use forward slashes
myFGDB = "C:/A/B/Test/TIMESLOOKUP.gdb"
# use double slashes
myFGDB = "C:\\A\\B\\Test\\TIMESLOOKUP.gdb"
So in your code, change this: arcpy.env.workspace = r"C:\A\B\Test\TIMESLOOKUP.gdb"
arcpy.env.scratchWorkspace = r"C:\A\B\Test\TIMESLOOKUP.gdb" to this: arcpy.env.workspace = r"C:\A\B\Test\TIMESLOOKUP.gdb"
arcpy.env.scratchWorkspace = r"C:\A\B\Test\TIMESLOOKUP.gdb" The other thing will probably be the table "LOOKUP$". Is this by any chance an Excel worksheet? If so, you will have to reference it with its complete path, since it is not in your current workspace (which is a fgdb). If you run this in the Python window of ArcMap and the table is named like that and in your TOC, it might just work. Kind regards, Xander BTW: good catch with the outWS
... View more
12-05-2013
02:13 AM
|
0
|
0
|
1088
|
|
POST
|
Hi Matthew, Can you post your code using the "#" button? It is probably the way the workspace is defined. Kind regards, Xander
... View more
12-05-2013
01:50 AM
|
0
|
0
|
2334
|
|
POST
|
Hi Matthew, If I understand this correctly it could look like the code below. I assumed the following things: you have an input folder or fgdb (inWS) where your input rasters are stored fldName1 holds the name of the output raster (no path to folder of fgdb included) fldName2 holds the name of the input raster (stored in inWS) fldName3 is numeric output rasters will be written to the output folder of fgdb outWS The code will need some small changes in case your fields include locations too. import arcpy,os
inWS = r'c:\path\to\input\folder\or\filegdb.gdb' # input rasters are stored here
outWS = r'c:\path\to\output\folder\or\filegdb.gdb' # output rasters will be stored here
tbl = 'YourTableName'
fldName1 = 'YourFieldName1' # field with output raster name (no path included)
fldName2 = 'YourFieldName2' # field with input raster name (no path included)
fldName3 = 'YourFieldName3' # multiply value field
fields = [fldName1,fldName2,fldName3]
with arcpy.da.SearchCursor(tbl, fields) as cursor:
for row in cursor:
value_from_row = row[2]
inName = row[1]
outName = row[0]
inRasLoc = os.path.join(inWS,inName)
inRas = arcpy.Raster(inRasLoc)
result = inRas * value_from_row
outRasLoc = os.path.join(outFolder,outName)
result.save(outName)
del row, inRas, tbl Kind regards, Xander
... View more
12-05-2013
12:44 AM
|
0
|
0
|
2334
|
|
POST
|
CAD data can be added to ArcMap directly without the use DataInterop. CAD data can also be used as input for the "Buffer (Analysis)" tool. Selections are honored. Results will be written to ArcGIS native formats (featureclass in geodatabase, shapefile, etc) not to CAD. Kind regards, Xander
... View more
12-04-2013
12:49 PM
|
0
|
0
|
468
|
|
POST
|
Since I already started with some Python code I decided to give it a go and I came up with some crappy code that actually results in a single 3D line. So this only processes a single line and the points that are within a distance of 1m tolerance to that line. It works for a test set and also the data Erin attached to this thread. It works like this: it converts the vertices of the line to a list (X,Y,Z,M,"line"), Z = None and M is distance from start the points are also converted to a list (X,Y,Z,M,"point"), Z has value and M is not set yet the lists are merged together (M for points is calculated) the first and last Z values are determined and set to the from and to points the intermediate vertices are provided with a Z value based on the known values and M locations of points the list is converted to a 3D polyline featureclass import arcpy,math
fcPnt = r'C:\Project\_Forums\Erin\Pipetest\points.shp'
fcLine = r'C:\Project\_Forums\Erin\Pipetest\pipe.shp'
fcLine3D = r'C:\Project\_Forums\Erin\test.gdb\pipe3D' # output
tolerance = 1
fldZpnt = "abs_height" # "SHAPE@Z"
# fetch polyline
with arcpy.da.SearchCursor(fcLine, ("SHAPE@")) as cursor:
for row in cursor:
polyline = row[0]
del row
# get sr from input lines
sr = arcpy.Describe(fcLine).spatialReference
# put polyline crds in list
lstPnts1 = []
arr = arcpy.Array()
dist = 0
pnt = arcpy.Point(0,0)
for arr in polyline:
for i in range(0,arr.count):
prevPnt = arcpy.Point(pnt.X,pnt.Y)
pnt = arr.next()
# Add distance from startpoint (M)
if i == 0:
dist = 0
else:
dist += math.hypot(pnt.X-prevPnt.X,pnt.Y-prevPnt.Y)
lstPnt = []
lstPnt.extend((pnt.X,pnt.Y,pnt.Z,dist,"line"))
lstPnts1.append(lstPnt)
##print "lstPnts1: {0}\n".format(lstPnts1)
lstPnts2 = []
cnt = 0
with arcpy.da.SearchCursor(fcPnt, ("SHAPE@X","SHAPE@Y",fldZpnt)) as cursor:
for row in cursor:
cnt += 1
lstPnt = []
lstPnt.extend((row[0],row[1],row[2],-1,"point"))
lstPnts2.append(lstPnt)
del row
##print "lstPnts2: {0}\n".format(lstPnts2)
# merge lists together
lstPnts3 = []
# loop through segments of polyline
for i in range(1,len(lstPnts1)):
X1,Y1,Z1,M1,geom1 = lstPnts1[i-1]
X2,Y2,Z2,M2,geom2 = lstPnts1
pnt1 = arcpy.Point(X1,Y1)
pnt2 = arcpy.Point(X2,Y2)
arrLine = arcpy.Array()
arrLine.add(pnt1)
arrLine.add(pnt2)
line = arcpy.Polyline(arrLine)
if i==1:
lstPnts3.append(lstPnts1[i-1])
for j in range(0,len(lstPnts2)):
Xn,Yn,Zn,Mn,geomn = lstPnts2
pntn = arcpy.Point(Xn,Yn)
dist = line.distanceTo(pntn)
if dist < tolerance:
# determine M value, assume point is "on" line
Mn = M1 + math.hypot(X1-Xn,Y1-Yn)
lstPnt= []
lstPnt.extend((Xn,Yn,Zn,Mn,geomn))
lstPnts3.append(lstPnt)
lstPnts3.append(lstPnts1)
##print ""
##print "X\tY\tZ\tM\tGeometry"
##for p in lstPnts3:
## print "{0}\t{1}\t{2}\t{3}\t{4}".format(p[0],p[1],p[2],p[3],p[4]).replace('.',',')
##print ""
# no extrapolation, just propagate last know Z
firstZ = None
lastZ = None
cnt=-1
for p in lstPnts3:
cnt+=1
if p[2] != None:
lastZ = p[2]
if firstZ == None:
firstZ = p[2]
##print ""
##print "first Z: {0}".format(firstZ)
##print "last Z: {0}".format(lastZ)
##print ""
# update firstZ and lastZ for from and to point
lstPnts3[0][2] = firstZ
lstPnts3[len(lstPnts3)-1][2] = lastZ
##print ""
##print "X\tY\tZ\tM\tGeometry (lastZ en firstZ)"
##for p in lstPnts3:
## print "{0}\t{1}\t{2}\t{3}\t{4}".format(p[0],p[1],p[2],p[3],p[4]).replace('.',',')
##print ""
# now fill up the blanks
print "Fill up the blanks"
cnt=-1
for p in lstPnts3:
cnt+=1
if p[2] == None:
currM = p[3]
# get known Z,M before current point
for i in range(cnt-1,0,-1):
if lstPnts3[2] != None:
beforeM = lstPnts3[3]
beforeZ = lstPnts3[2]
break
# get known Z,M after current point
for i in range(cnt+1,len(lstPnts3),1):
if lstPnts3[2] != None:
afterM = lstPnts3[3]
afterZ = lstPnts3[2]
break
if afterM - beforeM > 0:
currZ = beforeZ + (afterZ - beforeZ) * (currM - beforeM) / (afterM - beforeM)
else:
# in case of 2 points on same location...
currZ = beforeZ
lstPnts3[cnt][2] = currZ
##print ""
##print "X\tY\tZ\tM\tGeometry"
##for p in lstPnts3:
## print "{0}\t{1}\t{2}\t{3}\t{4}".format(p[0],p[1],p[2],p[3],p[4]).replace('.',',')
##print ""
# time to write the 3D line to a featureclass
features =[]
arr = arcpy.Array()
for p in lstPnts3:
if p[4] == "line":
pnt = arcpy.Point(p[0],p[1],p[2],p[3])
pntg = arcpy.PointGeometry(pnt,sr,True,True)
arr.add(pnt)
polyline3D = arcpy.Polyline(arr,sr,True,True)
features.append(polyline3D)
arcpy.CopyFeatures_management(features, fcLine3D)
print "ready..." Maybe this is useful to someone... Kind regards, Xander
... View more
12-04-2013
11:00 AM
|
0
|
0
|
1553
|
|
POST
|
Maybe this is caused by the lock on the data. What you could do is close the mxd that has references to the data and try again. I tried it with the small data sample you posted and some random points and it works: [ATTACH=CONFIG]29562[/ATTACH] Kind regards, Xander BTW; I run this as standalone script in PyScripter with ArcGIS 10.2
... View more
12-04-2013
03:28 AM
|
0
|
0
|
1235
|
|
POST
|
After looking at the problem some more, I decided to use IDW (from the geostatistical analyst extension) to interpolate a raster from the points instead of creating a TIN, with an extent beyond the lines, then I used interpolate shape. This seemed to work okay and the results look good to me. But perhaps someone knows a reason why this isn't a good method? Hi Erin, It is a good approximation, but keep in mind that IDW will not contain the actual value at the location where the points are known. It will smoothen the result, but maybe it's within your required precision. Kind regards, Xander
... View more
12-04-2013
12:59 AM
|
0
|
0
|
1553
|
| Title | Kudos | Posted |
|---|---|---|
| 6 | 12-20-2019 08:41 AM | |
| 1 | 01-21-2020 07:21 AM | |
| 2 | 01-30-2020 12:46 PM | |
| 1 | 05-30-2019 08:24 AM | |
| 1 | 05-29-2019 02:45 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-26-2025
02:43 PM
|