|
POST
|
From the image you include I think there are 4 different triangles that can be created, and you could change the start/end points for each triangle. There is a thing to keep in mind when doing a cost distance and a subsequent least cost path analysis including a weight based on the slope. In a slope map the cells hold the maximum slope of that cell in relation to its neighbors. You can however cross a cell in different ways (uphill, downhill or going straight). To compensate you could combine an aspect map with the slopes and assume that that a certain aspect is uphill and the opposite is downhill... Below a link to a thread on hiking speeds, that might be interesting: Hiking equation in python returns wrong results Kind regards, Xander
... View more
08-20-2014
06:25 AM
|
0
|
2
|
1634
|
|
POST
|
Sounds nice! To connect A to B passing by the lake, you should probably calculate path A - Lake and Lake - B separately. To enhance the analysis you could include a visibility (viewshed) analysis where the areas with visibility to the lake get a lower weight than the other pixels. This way you will force the route to have more views to the lake. If this will actually create a better path, depends strongly on the topography and landcover. Kind regards, Xander
... View more
08-20-2014
06:02 AM
|
1
|
1
|
1198
|
|
POST
|
It might help if you post a sample of your data and explain in more detail what type of chart you want to create and what need to be done with the "repeats" (redundancy) in the data. Also include the version of the software you´re using. Kind regards, Xander
... View more
08-20-2014
05:56 AM
|
0
|
0
|
2304
|
|
POST
|
Hi Paul, I'm glad it worked. Be aware that it creates the output in the same folder as the input. A second run would try to perform the same action on both the input and output files from the previous run. It might be better to create a separate workspace (folder) for the outputs. Like this:
def main():
# specify the workspace
ws = r"C:\Users\PaulBritten\Desktop\tenure\All reserves"
ws_out = r"C:\Users\PaulBritten\Desktop\tenure\YourOutputFolder" # should exist
arcpy.env.workspace = ws
arcpy.env.overwriteOutput = True
lst_fc = arcpy.ListFeatureClasses()
for fc in lst_fc:
name, ext = os.path.splitext(fc)
fc_out = "{0}_merged{1}".format(name, ext)
MergePolygonsOnDate(os.path.join(ws, fc), os.path.join(ws_out, fc_out))
... View more
08-20-2014
05:19 AM
|
1
|
1
|
591
|
|
POST
|
Owen is right, TIN's are not supported as parameter in a geoprocessing service. In case the TIN's are pretty much static you could include them in your script, without being parameters. If you have multiple TIN's then you could provide some intelligence (for instance the extent) in your script to use those needed for the provided input featureclass. Kind regards, Xander
... View more
08-19-2014
07:45 PM
|
0
|
0
|
1702
|
|
POST
|
the 5th edition was released in june 2013: Learning Python, 5th Edition
... View more
08-19-2014
07:34 PM
|
0
|
0
|
3973
|
|
POST
|
When I try the code below which copies the source to dest1 and dest2 (featureclass in a feature dataset), it works without any problem in 10.2.2.
import arcpy
arcpy.env.overwriteOutput = True
source = r"C:\Forum\overwrite\source.gdb\myFC"
dest1 = r"C:\Forum\overwrite\dest1.gdb\myFC"
dest2 = r"C:\Forum\overwrite\dest2.gdb\featDS\myFC"
arcpy.Copy_management(in_data=source,out_data=dest1,data_type="FeatureClass")
arcpy.Copy_management(in_data=source,out_data=dest2,data_type="FeatureClass")
The only way I could reproduce this error was trying to write to the dest2 featureclass without using the feature dataset in the path. Like this:
dest2 = r"C:\Forum\overwrite\dest2.gdb\myFC"
Are you sure you are using the output feature dataset in referencing the output featureclass? Kind regards, Xander
... View more
08-19-2014
07:11 PM
|
1
|
2
|
2546
|
|
POST
|
I tried to reproduce this and created a shapefile with 3 points and added the attributes as displayed in your example (leaving two fields untouched). You visualize them as <Null>, but a DBF does not have <Null> values as in a geodatabase table. I change the code to show what it actually prints and it seems to be a single space... When testing against a single space it detects the "<Null>" values.
import arcpy
def findAnimal(shp):
fields = ('NAME','CAT','DOG')
cursor = arcpy.da.UpdateCursor(shp,fields)
for row in cursor:
nameStr = row[0]
if nameStr[0:3] == "***":
if row[2] != " ":
print row[0]
print "'{0}'".format(row[2])
cursor.updateRow(row)
fc = r"C:\Forum\CatsDogs\CatsDogs.shp"
findAnimal(fc)
Kind regards, Xander
... View more
08-19-2014
06:32 PM
|
2
|
1
|
7162
|
|
POST
|
Since I don't know what your data looks like and I don't know where it is located, I just created an arbitrary polygon (triangle) over a set of test data pulled from a different thread. When you run your original code this should create the shapefile "X:/Users/Graphics.shp". Is this shapefile created correctly? Does it overlay with your data in the shapefile "X:/Users/ROUTE_SHAPES.shp"? Is your data frame, where you are drawing your line geometry, in the same projection? Those would be the first places to check. If the code is now working satisfactory then there may have been something with perhaps a previous shapefile that may have been conflicting... Do you remove the "Graphics.shp" or have you configured the option to overwrite the output in case it exists? I included this in my code to avoid problems. Since you are creating a tool (which I suppose you want to use more than once) and the intermediate and output results are hard coded (those will be the same each time you run the tool) you will need to include some handling of overwriting existing files. Kind regards, Xander
... View more
08-19-2014
06:10 PM
|
0
|
1
|
3203
|
|
POST
|
Interesting, but not what I was hoping for... I suppose that you do have access to an Advanced license, right? I noticed that the "Feature To Polygon" tool requires that type of license. I do not have one available at the moment. I did rewrite the code to work as stand alone, so I can test it easier and to solve the "Feature To Polygon", in the code I create an empty featureclass (lines 17 - 25) and write the polygon to it (lines 28 - 29). The line geometry is created on lines 34 - 39.
import arcpy
arcpy.env.overwriteOutput = True
def testing(line_geometry):
fc_routes = r"D:\Xander\GeoNet\ClipTool\ROUTE_SHAPE.shp"
fc_graphics = r"D:\Xander\GeoNet\ClipTool\GRAPHICS.shp"
fc_result = r"D:\Xander\GeoNet\ClipTool\POLYGON.shp"
array = arcpy.Array()
part = line_geometry.getPart(0)
for pt in part:
array.add(pt)
array.add(line_geometry.firstPoint)
polygon = arcpy.Polygon(array, fc_routes)
# create empty shapefile
geometry_type = "POLYGON"
template = ""
has_m = "DISABLED"
has_z = "DISABLED"
sr = arcpy.Describe(fc_routes).spatialReference
ws_path, fc_out_name = os.path.split(fc_graphics)
arcpy.CreateFeatureclass_management(ws_path, fc_out_name,
geometry_type, template, has_m, has_z, sr)
# FeatureToPolygon_management requires Advanced
with arcpy.da.InsertCursor(fc_graphics, ("SHAPE@")) as curs:
curs.insertRow((polygon,))
arcpy.Clip_analysis(fc_routes, fc_graphics, fc_result)
# create a line geometry
array = arcpy.Array([arcpy.Point(467075, 211310),
arcpy.Point(467550, 214930),
arcpy.Point(470900, 212561)])
polyline = arcpy.Polyline(array)
line_geometry = arcpy.Polyline(array)
# call the clip function
testing(line_geometry)
This did work without problems: Can you check your graphics shapefile to see if it has the desired content? Kind regards, Xander
... View more
08-19-2014
02:39 PM
|
1
|
3
|
3203
|
|
POST
|
Maybe it's because the clip features "Graphics.shp" is not assigned a coordinate system? You can do this by changing the line where you create the polygon to this:
polygon = arcpy.Polygon(array, "X:/Users/ROUTE_SHAPES.shp")
... View more
08-19-2014
01:53 PM
|
0
|
5
|
3203
|
|
POST
|
Hi Paul, Don't worry, that what the forum is all about... to help one another. Have a look at the code below. The majority is placed inside a function "MergePolygonsOnDate". The main function (lines 13 - 23) contains the logic for looping through your featureclasses. It will create a list of all the featureclasses in you workspace. Based on the input name it will create the new output names. On line 23 for each featureclass the "MergePolygonsOnDate" is called. I haven't tested the code, so if you run into problems, just post it and I'll have a look.
#-------------------------------------------------------------------------------
# Name: MergePolygonsOnDate_v3.py
# Purpose: Merge polygons on date range
#
# Author: xbakker
#
# Created: 19/08/2014
#-------------------------------------------------------------------------------
import arcpy, os
from datetime import datetime, timedelta
def main():
# specify the workspace
ws = r"C:\Users\PaulBritten\Desktop\tenure\All reserves"
arcpy.env.workspace = ws
arcpy.env.overwriteOutput = True
lst_fc = arcpy.ListFeatureClasses()
for fc in lst_fc:
name, ext = os.path.splitext(fc)
fc_out = "{0}_merged{1}".format(name, ext)
MergePolygonsOnDate(os.path.join(ws, fc), os.path.join(ws, fc_out))
def MergePolygonsOnDate(fc, fc_out):
# change settings
fld_start = "DateFrom" # create date field and fill it with content of StartDate
fld_end = "DateTo" # create date field and fill it with content of EndDate
fld_name = "Name"
fld_outname = "OutputName" # output name
len_outname = 75
# create empty output shapefile
ws_path, fc_out_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(ws_path, fc_out_name,
"POLYGON", fc, "SAME_AS_TEMPLATE", "SAME_AS_TEMPLATE", fc)
# add string field
arcpy.AddField_management(fc_out, fld_outname, "TEXT", "", "", len_outname)
flds = ("SHAPE@", fld_start, fld_end, fld_name)
flds_out = ("SHAPE@", fld_start, fld_name, fld_outname)
# create a unique list of dates from start date
lst_dates = list(set([row[0] for row in arcpy.da.SearchCursor(fc, (fld_start))]))
lst_dates.sort()
# insert cursor to store features to new featureclass
with arcpy.da.InsertCursor(fc_out, (flds_out)) as curs_out:
# loop through list of unique dates
for date in lst_dates:
# create an expression
expression = "{0} <= date '{2}' AND {1} >= date '{2}'".format(
arcpy.AddFieldDelimiters(fc, fld_start),
arcpy.AddFieldDelimiters(fc, fld_end), date)
i = 0
# create the searchcursor with the expression
with arcpy.da.SearchCursor(fc, flds, where_clause=expression) as curs:
for row in curs:
pol = row[0]
name = row[3] # take name of first polygon
if i == 0:
# first polygon is just the polygon"
polygon = pol
else:
# next polygons are added with union
polygon = polygon.union(pol)
i += 1
# insert the feature into the output featureclass
datefrom = date
i_date = lst_dates.index(date)
if i_date + 1 > len(lst_dates) - 1:
dateto = ""
outname = "{0} {1} - {2}".format(name, datefrom.strftime('%Y/%m/%d'), dateto)
else:
dateto = lst_dates[i_date + 1] - timedelta(days=1)
outname = "{0} {1} - {2}".format(name, datefrom.strftime('%Y/%m/%d'), dateto.strftime('%Y/%m/%d'))
curs_out.insertRow((polygon, row[1], name, outname))
if __name__ == '__main__':
main()
... View more
08-19-2014
11:53 AM
|
2
|
3
|
1682
|
|
POST
|
Hi Dan Patterson, Actually, to be honest I haven't given it much thought yet as to what content it should contain. But since it is called "python snippets" and due to the fact that a pure python snippet (read "Arc-less") can be very helpful in Arc*** projects, I don't think it should be restrained to arcpy related content only. My intention was to put some snippet in this place and see where it leads. I haven't been able to do that yet, but hope to do so, when my schedule allows it. You have at your blog a very valuable collection of resources. I don't think the idea should be to duplicate it, but a reference to your blog would be very helpful. The complexity of the snippets doesn't have to be reduced to only for beginners or only advanced. Maybe what I would like it to share snippets that helped one and could be helpful to others, preferably with some explanation of how it works. I am open for suggestions. Dan, do you have any ideas on how this place could benefit the community? Kind regards, Xander
... View more
08-19-2014
10:36 AM
|
0
|
0
|
1000
|
|
POST
|
Hi Lance, As long as you know what you need, there is no problem whatsoever on summarizing on unique length. Good luck, Xander
... View more
08-18-2014
11:03 AM
|
1
|
0
|
3112
|
|
POST
|
Hi Paul, That is possible, but it might be necessary to know a little more on the folder structure where you have your input featureclasses and how you want to name the outputs. Normally a arcpy.ListFeatureclasses() can be used to get a list of featureclasses in the current workspace. In case they are in multiple folders and sub folders the arcpy.da.Walk() is better. Based on the input name, you can create an outputname (like for instance inputname_merged). The current script can be rewritten as a function to process a single featureclass. This function will be called from the loop through the input featureclasses. Kind regards, Xander
... View more
08-18-2014
11:00 AM
|
0
|
5
|
1682
|
| 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 |
Tuesday
|