POST
|
Hi, Thanks for the very prompt reply! However, I can't quite see how to use those tools to do what I want. The Identity and Update tools state in the help that they require at least one of the inputs to be a polygon, and sadly all of my inputs are polylines. Do you have any ideas how to get around this? It looks like I might be able to use the Intersect tool to create points at the intersections, and then join those up with new lines...maybe. Any further ideas? Cheers, Robin
... View more
02-07-2011
11:03 PM
|
0
|
0
|
631
|
POST
|
Hi, Is there a way, in Python using ArcPy, to split a line at the intersections with the other lines. That is, if I have a long line which intersects many other lines, I'd like to split the long line into a number of shorter lines - split at the intersections. Is this possible? Cheers, Robin
... View more
02-07-2011
10:37 PM
|
0
|
5
|
4154
|
POST
|
In this case I'd suggest writing to CSV (comma separated values) files, as they can easily be read both as text files and in Excel (and other spreadsheet packages). As for how to write them in Python, there are a number of options: You could simply write the data using the standard text file writing python commands (see http://snipplr.com/view/6630/reading-and-writing-text-files-in-python/ for a simple tutorial) and put comma's between them. For example, I used the following code in one of my projects: # Open the file
FILE = open(output_file, "a")
# Write the header (so I can remember what each column is!)
FILE.write("name,n,mean_len,total_len,max_len,min_len,stdev_len,mean_closeness,std_closeness,defect_dens,r_score,z_score,p_value\n")
# Get the line that I need to write to the CSV file (it is returned from a function I wrote to do my processing)
csv_line = process_file(full_path)
# Print it to the screen (just for testing really)
print csv_line
# Write it to the file
FILE.write(csv_line + "\n")
# Close the file
FILE.close() Of course, I also had some code within the process_file() function which created the line of CSV to write: # Put all of the statistics into a list - in this case all of the items in the list are variables that I have calculated
output_stats = [tidied_file_name, n_dunes, mean_len, total_len, max_len, min_len, stdev_len, mean_closeness, std_closeness, defect_dens, r_score, z_score, p_value]
# For each of the items in this list, convert it to a string and append to an array
for item in output_stats:
csv_array.append(str(item))
# Join this array, adding commas between all the items
csv_string = ",".join(csv_array)
# Return this comma joined array ready to write to the file
return csv_string The alternative is to use a Python library like the CSV library (http://docs.python.org/library/csv.html) which comes with functions to read and write CSV files. Hope that helps, Robin
... View more
01-31-2011
01:14 PM
|
0
|
0
|
320
|
POST
|
Hi, I have a number of roughly-parallel polylines in a Shapefile. I would like to calculate an average spacing of these polylines by using a number of transects across the area covered by my lines. I need to be able to script this, so that it can be run as an unattended script, but I can't think of how best to go about it in Python. Does anyone have any ideas? Is there a tool that will break a line (the transect) into a number of small lines with the breaks occurring everywhere that it intersects another line? That would seem to me to be the easiest way to do it, as calculating the spacing would just involve calculating the length of the split lines, but I can't seem to see a way to do it. Is this possible? If not, what would people suggest?
... View more
01-31-2011
12:56 PM
|
0
|
0
|
691
|
POST
|
I'm afraid I haven't got an installation of Python 2.5 to test this on, but whenever I use GDAL I import it as follows: from osgeo import gdal This is because the gdal module is located inside the osgeo module. Let me know if that works, Robin
... View more
01-22-2011
08:20 AM
|
0
|
0
|
303
|
POST
|
Hi, I am trying to calculate which polylines in my dataset overlap with each other, and can't seem to get it to work. The basic procedure that I'm using is to loop through my features, and then have a second inner loop that loops through the features again and finds out which ones the first feature overlaps with. However, I end up with nothing showing as overlapping (even though some of my features are definitely overlapping). I tried this with some of the other geometry methods such as touches, within, crosses etc, and they also seem to give strange results. For example, I get nothing showing as touching, overlapping, crossing etc, but then also nothing showing as disjoint - which doesn't seem to make sense. My python code is below, it's quite possible that I've made an elementary error: import arcpy input_lines = "D:\\Data\\DunesGIS\\TestOverlaps.shp" rows = arcpy.SearchCursor(input_lines) shape_name = arcpy.Describe(input_lines).shapeFieldName for row in rows: shape = row.getValue(shape_name) comparison_rows = arcpy.SearchCursor(input_lines) for comparison in comparison_rows: comparison_shape = row.getValue(shape_name) #print comparison_shape if shape.overlaps(comparison_shape): print "FOUND IT!!" del comparison_rows print "Done" del rows
... View more
01-21-2011
01:43 AM
|
0
|
1
|
585
|
POST
|
Hi, I'm looking for a tool that will calculate the angle of each line in a set of polylines individually. Ideally I would like to be able to add an extra field to the attribute table of the polylines and fill this field with the overall angle of the polyline (probably just calculated from the first point to the last point, ignoring the bits in the middle). Is there a tool that will do this? I can find various tools that will work for polygons, but not for polylines. Cheers, Robin
... View more
01-20-2011
01:03 PM
|
0
|
8
|
46364
|
POST
|
Hi, Is there any way to access the tools in the ArcScan extension from within a Python script? I particularly want to use the ArcScan vectorisation tool from within my script. Alternatively, is there any other semi-intelligent vectorisation tool I can use from within my python scripts? The standard Raster to Polyline conversion doesn't seem to cope at all well with my data. Cheers, Robin
... View more
01-20-2011
11:08 AM
|
0
|
3
|
1095
|
POST
|
Thanks - that looks great. Is there any difference between the Unsplit Lines tool and the Dissolve tool with the Unsplit Lines checkbox ticked? It doesn't look like there is, but I thought I'd check. Also, does anyone know a way to do this with distance tolerances too (that is, merging lines that are within a certain distance of another line, instead of having to touch the line).
... View more
01-19-2011
12:45 PM
|
0
|
0
|
227
|
POST
|
I have a shapefile with a lot (around 9000) line features in it. Many of these line features are either touching, or very close to touching, and I would like to merge these ones into one feature. Ideally I would then end up with a shapefile with around 50 features in it, each of which would have been merged from the features that were touching. How should I do this from python? I know I can do it manually from the editor toolbar with the merge tool, but I can't seem to find how to do this programmatically. I've searched in various places and can't seem to find an answer. Does anyone have any ideas?
... View more
01-19-2011
05:51 AM
|
0
|
3
|
342
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|