|
POST
|
Ok, I just tried some code using (I think) only 10.0 functionality. So Gaston Izaguirre, if you want to try, give it a shot here is some code: Change the code on line 3 and 4 to point to your input polyline featureclass and output point featureclass (output will be created, if it exists it raises an error). Line 5 contains the interval size (distance between each point) and line 6 indicates if the last point should be added too (True). import arcpy, math, numpy
def main():
fc_in = r"D:\Xander\GeoNet\Polyline2Points10.0\test.gdb\lines_diss_projected"
fc_out = r"D:\Xander\GeoNet\Polyline2Points10.0\test.gdb\lines_diss_toPnts01"
interval = 100
bln_addLastPoint = True
fld_shp = arcpy.Describe(fc_in).shapeFieldName
sr = arcpy.Describe(fc_in).spatialReference
curs = arcpy.SearchCursor(fc_in)
pnts = []
for row in curs:
polyline = row.getValue(fld_shp)
d = 0
frac_left = 0
for p in range(0, polyline.partCount):
part = polyline.getPart(p)
for i in range(0, len(part)-1):
pnt1 = part
pnt2 = part[i+1]
length_part = getDistance2Points(pnt1, pnt2)
for frac in numpy.arange(frac_left, length_part, interval):
pnt = getPointBasedOnFractionOfLine(pnt1, pnt2, frac)
pntg = arcpy.PointGeometry(pnt, sr)
pnts.append(pntg)
frac_left = interval - (length_part - frac)
if bln_addLastPoint:
pnts.append(arcpy.PointGeometry(polyline.lastPoint, sr))
del curs, row
# write list to output featureclass
arcpy.CopyFeatures_management(pnts, fc_out)
def getDistance2Points(pnt1, pnt2):
return math.hypot(pnt1.X-pnt2.X, pnt1.Y-pnt2.Y)
def getPointBasedOnFractionOfLine(pnt1, pnt2, frac):
length_line = getDistance2Points(pnt1, pnt2)
f = frac / length_line
return arcpy.Point(pnt2.X * f + pnt1.X * (1-f), pnt2.Y * f + pnt1.Y * (1-f))
if __name__ == '__main__':
main()
... View more
01-15-2015
08:42 AM
|
0
|
0
|
1286
|
|
POST
|
An alternative would be to use the Densify tool to create points every x meter on the line followed by te Feature Vertices to Points tool (if you have access to those tolos).
... View more
01-15-2015
03:54 AM
|
1
|
0
|
1286
|
|
POST
|
The da.SearchCursor could be easily replaced with the "old" SearchCursor, but what would be more work is to rebuild the positionAlongLine method, which is not available at 10.0. You may want to post your own question with that specific detail. I guess that would attract more people to help you with that problem. However, I will have a look to see if I can easily solve it, but I do not have access to 10.0 anymore. Kind regards, Xander
... View more
01-15-2015
03:48 AM
|
1
|
2
|
1286
|
|
POST
|
Did you try the Mean Center and Median Center (Spatial Statistics) tools? ArcGIS Help (10.2, 10.2.1, and 10.2.2) Use the case field to identify the points for each intersection.
... View more
01-14-2015
07:39 PM
|
2
|
0
|
4015
|
|
POST
|
The code would look like the code below. Notice the following changes: Line 6 holds the interval, I changed it from 1 to 3, so now it picks points every 3 meters on each contour line. Line 14 contains a where clause that filters the contour lines with Contour > 1000 Line 21 applies the where clause import arcpy, os
fc_in = r"C:\Forum\Pasture\gdb\Contours.gdb\contours2"
fc_out = r"C:\Forum\Pasture\gdb\Contours.gdb\contour_pnts03"
fld_contour = "Contour"
interval = 3 # pick points every x meter on every contour line
# create empty output featureclass
sr = arcpy.Describe(fc_in).spatialReference
out_ws, out_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(out_ws, out_name, "POINT", fc_in, "DISABLED", "DISABLED", sr)
# create a where clause
where = "{0} > {1}".format(arcpy.AddFieldDelimiters(fc_in, fld_contour), 1000)
# add field with contour value to output fc
arcpy.AddField_management(fc_out, fld_contour, "DOUBLE")
cnt = 0
with arcpy.da.InsertCursor(fc_out, ("SHAPE@", fld_contour)) as curs_out:
with arcpy.da.SearchCursor(fc_in, ("SHAPE@", fld_contour), where_clause=where) as curs_in:
for row_in in curs_in:
polyline = row_in[0]
contour = row_in[1]
max_len = polyline.length
d = 0
while d < max_len:
pnt = polyline.positionAlongLine(d, False)
curs_out.insertRow((pnt.firstPoint, contour, ))
cnt += 1
if cnt % 100 == 0:
print "Processing point: {0}".format(cnt)
# pnt.firstPoint
d += interval
curs_out.insertRow((polyline.lastPoint, contour, ))
cnt += 1
... View more
01-14-2015
06:26 PM
|
0
|
0
|
2066
|
|
POST
|
You could use: arcpy.env.workspace = r"c:\temp\tmp" or create a file geodatabase and point to that location.
... View more
01-14-2015
04:37 PM
|
1
|
14
|
2137
|
|
POST
|
Can you post a part of your data? It will be difficult to trace the error without it. Is the DEM an integer or is it floating? If it is floating then it will not have an attribute table and the code will fail. The other things is, today I tried an da updatecursor on an integer raster and it didn't work, while the old update cursor did work. Not sure if that should be changed.
... View more
01-14-2015
04:35 PM
|
1
|
34
|
3580
|
|
POST
|
Yep that is a memory problem (due to the size of your raster). You can change the "IN_MEMORY" on line 8 to an existing file geodatabase or scratch geodatabase, so it doesn't try to do it in memory
... View more
01-14-2015
04:25 PM
|
1
|
16
|
2137
|
|
POST
|
never mind... Find attached the toolbox with the script tool inside. You can drag and drop this script tool into your model and connect it: The code of the script is as follows: import arcpy
from arcpy import env
from arcpy.sa import *
#Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "IN_MEMORY"
# input parameters
LULC = arcpy.GetParameterAsText(0) # r"D:\Xander\GeoNet\LULC\data\viet_LULC_450.tif"
Simard = arcpy.GetParameterAsText(1) # r"D:\Xander\GeoNet\LULC\data\MajoritySTOht_450.tif"
ras_LULC = Raster(LULC)
ras_Simard = Raster(Simard)
# output parameter
result = arcpy.GetParameterAsText(2) # r"D:\Xander\GeoNet\LULC\data\MajoritySTOhtPer.tif"
# internal vars
fld_value = "Value"
fld_remap = "remap"
# remap dictionary
dct = {1 : 0.4, 2 : 0.4, 3 : 0.4, 4 : 0.4, 5 : 0.4, 6 : 0.3, 7 : 0.3,
8 : 0.3, 9 : 0.3, 10 : 0.3, 11 : 0, 12 : 0.3, 13 : 0, 14 : 0.3}
# add field for remap values
arcpy.AddField_management(ras_LULC, fld_remap, "DOUBLE")
# update the remap values base on dictionary
curs = arcpy.UpdateCursor(ras_LULC)
for row in curs:
val = row.getValue(fld_value)
if val in dct:
remap = dct[val]
else:
# what should be done with the values in the TIFF that are not in your list?
remap = 0 # val?
row.setValue(fld_remap, remap)
curs.updateRow(row)
del curs, row
# remap the raster
ras_remap = Lookup(ras_LULC, fld_remap)
# create result
resultmap = ras_Simard * ras_remap
resultmap.save(result)
# release the SA license
arcpy.CheckInExtension("Spatial")
... View more
01-14-2015
01:23 PM
|
1
|
18
|
2137
|
|
POST
|
Good question. At first I thought that this should be available as standard tool in ArcGIS, but that seems not to be the case. Maybe it is because you can string the Densify and Feature Vertices to Points tools together and get the result, but this is not for all licenses available.
... View more
01-14-2015
01:04 PM
|
2
|
2
|
2066
|
|
POST
|
A few remarks: viet_LULC_30.tif is a large raster (2GB) with a resolution of 30 meters, but the detail inside is only using a resolution of 450m (was this raster resampled with a factor 15? If so, why?). I notice that it has values from -1 to 16. In your code you only account for value 1 to 14.Values -1, 0, 15 and 16 will remain untouched. Is that correct? One of the downloads (WRFV3.6.1.TAR.gz) seems to be C code. I asume this should not be used. MajoritySTOht.tif is not included in the downloads. Pease attach the version with 450m resolution to keep things small. The Toolbox Lee_Filtering contains 5 models. I won't touch these, I will simply show how to include the script in the model The script SRTMCorrectionTreeOffsets.py contains the code you originally po
... View more
01-14-2015
12:36 PM
|
1
|
20
|
2137
|
|
POST
|
I am glad it is working, and yes it can be a long process depending on the number of points that need to be generated. If you can use the standard Densify tool as Dan suggested, you could use the Feature Vertices to Points tool. This tool can convert a line into points, but will only convert the existing vertices (not create any new ones)
... View more
01-14-2015
12:03 PM
|
1
|
4
|
4854
|
|
POST
|
If you can include a small subset of your data I can have a look at the calculation you intent to do, since doing 14 calculations for what can be done in one, doesn't sound correct to me. You would have to adapt the code to allow for parameters: http://resources.arcgis.com/en/help/main/10.2/index.html#/Understanding_script_tool_parameters/00150000002s000000/ I suppose all things listed below should be change into parameters. So something like this: env.workspace = arcpy.GetParameterAsText(0)
LULC = Raster(arcpy.GetParameterAsText(1))
Simard = Raster(arcpy.GetParameterAsText(2))
resultmap.save(arcpy.GetParameterAsText(3))
instead of this: env.workspace = "c:\DEMPreProcess"
LULC = Raster("C:\DEMPreProcess\VietnamLULC_Resample.tif")
Simard = Raster("C:\DEMPreProcess\MajoritySTOht.tif")
resultmap.save("C:\DEMPreProcess\MajoritySTOhtPer.tif")
... View more
01-14-2015
11:24 AM
|
1
|
22
|
2137
|
|
POST
|
In the upper right corner of the editor (when editing a post) you will see the link "Use advanced editor". The code you supplied is Python code. It is possible that Visual Studio has been used to run it, but the IDE has no influence on the code itself.
... View more
01-14-2015
10:41 AM
|
1
|
27
|
3040
|
|
POST
|
Do you only want to obtain the attributes (in that case the solution by Jeff could be sufficient, although you should check stations near intersections) or do you want to move the points towards the network?
... View more
01-14-2015
10:15 AM
|
0
|
0
|
1310
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-09-2020 09:26 AM | |
| 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 |
| Online Status |
Offline
|
| Date Last Visited |
3 weeks ago
|