|
POST
|
I wonder if the code is correct. Seems to me there are a few strange things going on. On the next line there are two brackets missing:
b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID'),DefQ)
should probably be:
b = sum([row[0] for row in arcpy.da.SearchCursor(fc, ('QUANTITY_SOLID'),DefQ)])
First to create a list of unique values in a field you can do that on a single line like this:
# find the unique 'SEGMENT_LENGTH' values, maybe use SHAPE@LENGTH instead?
lst_seglen = list(set([row[0] for row in arcpy.da.SearchCursor(fc, ('SEGMENT_LENGTH'))]))
I would probably do it differently and use a dictionary to store the unique length vs the sum of the Quantity Solid. Next a simple update cursor to store the results.
def f(fc):
dct = {}
flds = ('SEGMENT_LENGTH', 'QUANTITY_SOLID')
with arpy.da.SearchCursor(f, flds) as curs:
for row in curs:
if row[0] in dct:
dct[row[0]] += row[1]
else:
dct[row[0]] = row[1]
flds = ('SEGMENT_LENGTH', 'QUANTITY_SOLID_SUM')
with arcpy.da.UpdateCursor(fc, flds) as curs:
for row in curs:
if row[0] in dct:
row[1] = dct[row[0]]
else:
row[1] = 0 # should not occur
cursor.updateRow(row)
return fc
It still sounds strange to look for unique segment lengths and sum values for each unique length. Normally you see this the other way (sum length for a unique value)...
... View more
08-15-2014
09:10 PM
|
3
|
2
|
3112
|
|
POST
|
I doubt that raster fields are supported in ArcGIS Online, but maybe Bernie Szukalski can enlighten us on this topic. In case they are not supported, you could use some Python code to extract the rasters and store them on a server (or even dropbox) and create hyperlinks for each feature. The site below explains shortly how to export the rasters to files. How to export your raster datasets referenced in a “raster” attribute field (file geodatabase) using Python. | Esri Aus… Another option would be the use of attachments: Configure pop-ups—Help | ArcGIS Kind regards, Xander
... View more
08-15-2014
08:36 PM
|
0
|
1
|
1290
|
|
POST
|
Hi Drew, The client which I am advising at this moment, is taking its first steps with ArcGIS Online. Due to the confidentiality and the nature of the data and the analysis they conduct they might switch to Portal for ArcGIS, next to their custom developed ArcGIS for Server applications. You're right, Portal and AGOL4O both have their place. Kind regards, Xander
... View more
08-15-2014
08:04 PM
|
1
|
0
|
1781
|
|
POST
|
I was just thinking, I don't need the 10.2.1 functionality to do this. It is also possible to something like this:
# start insert cursor for output points
with arcpy.da.InsertCursor(fc_out, flds_out) as curs_out:
# start search cursor on lines
with arcpy.da.SearchCursor(fc_in, flds_in) as curs:
for row in curs:
number = 0
polyline = row[0]
line_ID = row[1]
chainage = 0
for part in polyline:
for pnt in part:
number += 1
if pnt:
ptGeom = arcpy.PointGeometry(pnt, sr)
if number > 1:
chainage += ptGeom.distanceTo(prev_pnt)
# chainage = polyline.measureOnLine(ptGeom)
elevation = pnt.Z
curs_out.insertRow((ptGeom, line_ID, number, elevation, chainage))
prev_pnt = ptGeom
It uses the distanceTo on the point geometry to sum the traveled distance on the line... Kind regards, Xander
... View more
08-15-2014
10:13 AM
|
0
|
0
|
3872
|
|
POST
|
Hi Peter, Since you are interested in Python, let's throw in some Python code. I haven't tested the code, since the measureOnLine method was introduced at 10.2.1 and I have a lower version here. The rest of the code seems to work though. Have a look at the code below: Lines 5 and 6 define the path to you input 3D lines and output points (which will be created in the process) Lines 9 to 12 define the column names. fld_ID should point at an existing field in you input featureclass, which will be transferred to the output points Lines 18 and 19 read some properties of the input featureclass, used to create the output pointfeatureclass and the ID field Lines 22 till 28 will create the empty point featureclass Lines 31 till 34 will add the output fields to the point featureclass lines 40 and 42 define the insert cursor (points) and search cursor (lines) Rest of the lines perform a loop through the points of each part of the polyline, and determine the values you're interested in Hope it works for you, good luck, Xander
import arcpy, os
arcpy.env.overwriteOutput = True
# featureclasses
fc_in = r"D:\Xander\GeoNet\3Dlines2Points\test.gdb\my3Dlines"
fc_out = r"D:\Xander\GeoNet\3Dlines2Points\test.gdb\myPoints"
# fields
fld_ID = "ID" # ID of Cross-Section in line featureclass
fld_Number = "Number" # just to add a number to the points
fld_Z = "Z" # Elevation
fld_Chainage = "Chainage" # Distance m from start of polyline
# fields for search cursor on input lines
flds_in = ("SHAPE@", fld_ID)
# get some input data to create the output
sr = arcpy.Describe(fc_in).spatialReference
ofld_ID = arcpy.ListFields(fc_in, fld_ID)[0]
# create the output featureclass
geometry_type = "POINT"
template = ""
has_m = "DISABLED" # you could enable M values...
has_z = "ENABLED"
ws_path, fc_out_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(ws_path, fc_out_name,
geometry_type, template, has_m, has_z, sr)
# add the fields to the point featureclass
arcpy.AddField_management(fc_out, fld_ID, ofld_ID.type)
arcpy.AddField_management(fc_out, fld_Number, "LONG")
arcpy.AddField_management(fc_out, fld_Z, "DOUBLE")
arcpy.AddField_management(fc_out, fld_Chainage, "DOUBLE" )
# fields for insert cursor on output points
flds_out = ("SHAPE@", fld_ID, fld_Number, fld_Z, fld_Chainage)
# start insert cursor for output points
with arcpy.da.InsertCursor(fc_out, flds_out) as curs_out:
# start search cursor on lines
with arcpy.da.SearchCursor(fc_in, flds_in) as curs:
for row in curs:
number = 0
polyline = row[0]
line_ID = row[1]
for part in polyline:
for pnt in part:
number += 1
if pnt:
ptGeom = arcpy.PointGeometry(pnt, sr)
chainage = polyline.measureOnLine(ptGeom)
elevation = pnt.Z
curs_out.insertRow((ptGeom, line_ID, number, elevation, chainage))
... View more
08-15-2014
10:03 AM
|
0
|
1
|
3872
|
|
POST
|
With respect to the placement of the labels, an option would be to use the optional points created in the Fishnet tool to label the cells. Since the points describe the center of the cell, the would have to be moved. This can be done with the FieldCalculator: At the fishnet tool switch on the option "Create label points" In the resulting point featureclass add a text field (for instance "labels") Let's first move the points using the FieldCalculator. Calculate the Shape field as follows: The pre-logic script is:
def TranslatePoint(pnt, x_shift, y_shift):
return arcpy.Point(pnt.firstPoint.X + x_shift, pnt.firstPoint.Y + y_shift)
At the "Shape =" part enter the formula: TranslatePoint( !Shape! , -1 * half your cell size, +1 * half your cell size) This will move the point half the cell size to the left and half the cell size up to go to the upper left corner. The next step will be to fill the labels field with the text for the labels; calculate the "labels" field: The pre-logic script is:
def GetCoord(pnt):
return "({0}, {1})".format(int(pnt.firstPoint.X), int(pnt.firstPoint.Y))
At the "labels =" part enter the formula: GetCoord( !Shape! ) This will create a text of "(Easting, Northing)". Use this field to label the points to get something like this: Kind regards, Xander
... View more
08-15-2014
08:22 AM
|
0
|
0
|
2168
|
|
POST
|
In that case the Fishnet would be the way to go. In the Fishnet dialog, specify your lower left corner (rounded coordinates, which should be multiples of the cell size) at "Fishnet Origin Coordinate". At "Y-axis coordinate" specify your upper left corner (I assume you don't have rotation) At Cell Size With and Height specify the size of your cell At Number of Rows specify the number of cells you want vertically and at number of Columns specify the number of cells you want horizontally. Select polygons as output geometry. This creates featureclass of the cell polygons. Now labeling is a different aspect. The fishnet created (and optional labels) don't have any additional information on the cell coordinates. However you can add this information through the FieldCalculator: Add a new text field Calculate the Field (right click on column header) Specify the following information: This will fill the newly added field with the text "(X value, Y value)". Labels the featureclass with this field. You can add an label expression to add additional text: "Upper left (E, N):" & vbnewline & [labels] This will create a label like: Upper left (E, N): (X value, Y value) The only point is, that the label will be centered in the cell. Kind regards, Xander
... View more
08-15-2014
07:16 AM
|
0
|
1
|
2168
|
|
POST
|
Hi J(?), If you use graticules the corners of the "cells" can be found at the border of the map. If you want to labels to show on the cell itself, I guess you would have to create the fishnet (physical layer) and label it. If you can visualize it a little more, I might be able to give you some pointers. Kind regards, Xander
... View more
08-15-2014
06:27 AM
|
0
|
0
|
2168
|
|
POST
|
Hi Paul, I think you could try something like this:
import arcpy, os
from datetime import datetime, timedelta
arcpy.env.overwriteOutput = True
# change path to datasource
fc = r"D:\Xander\GeoNet\MergePolsDate\Reserves_copy.shp"
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
# output shape
fc_out = r"D:\Xander\GeoNet\MergePolsDate\Reserves_merged3.shp"
# 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))
The code will create the output column with the format from your example Kind regards, Xander PS: If the answer responds you question mark the post as answered at the post that answered your question. If it was helpful, mark it as helpful. This way other forum users will be able to find useful content. More on GeoNet can be found here: GeoNet Help
... View more
08-14-2014
09:17 AM
|
2
|
12
|
3642
|
|
POST
|
Hi Paul, From your example I don't really understand the concept of a "financial year". To fill the EndDate columns with the value 31/21/2300 doesn't seem right, since polygons that expire before that date, but have an end date after the current processing date, are included too. It is possible to add the name and create a new column "OutputName" that holds the name and a date range. What is not very clear to me is this: For the first record in your Excel it seems that the current processing date is "31/03/1965". In the code I provided the first processing date will be "01/04/1962" which will create a name "Reserve A 01/04/1962 - 01/04/1962". For the next record it will include those polygons for which the start date is before or on the current processing date ("07/06/1965") and the end date is on or after the current date. This will include also the first record, creating an overlap in range and an OutputName "Reserve A 01/04/1962 - 07/06/1965" Since the first record in the sample shapefile has an end date of 31/21/2300 it will be included in all the features. Maybe you can explain a little more on what you are trying to achieve?
... View more
08-14-2014
07:52 AM
|
0
|
14
|
3642
|
|
POST
|
That's nice, I was't aware of this possibility. If the list get a little longer, you may want to consider using a dictionary, like this:
def FindLabel([YourFieldName]):
dct = {1: "Bob Hope", 2: "Bob Costas", 3: "Bob Marley",
4: "Bobby Bowden", 5:"Bob the Clown"}
district = int([YourFieldName])
if district in dct:
return dct[district]
else:
return "<ITA>Unknow supervisor</ITA>"
I used this on the feature ID (FID) field of a shapefile with values ranging from 0 to 7 and got this:
... View more
08-13-2014
12:21 PM
|
1
|
0
|
3237
|
|
POST
|
Hi Paul, I have included some Python code that created a new shapefile with the merged polygons. The attributes are still to be defined. In the code the processing date is assigned the the output date fields. Prerequisites: Create two new columns that hold the start and end date as date (not as text). You can do this by adding the fields "DateFrom" and "DateTo" as date fields Calculate the new fields and simply assign the field StartDate and EndDate to it The reason to do this is to simplify the syntax of the where clause used in the script. Configuration: Change line 6 to point to your input shapefile Change line 7 and 8 to hold the field names of the date fields (the newly added fields) Change line 11 to point to a shapefile that will be created The script will: Create an empty output shapefile Create a list of unique dates from the start date field Loop through each date and create an expression (see lines 29 - 31). It will select all polygons with a start date less than of equal to the current date and where the end dates are after the current date On lines 35 - 42 the polygons that match the query will be merged into a single (multipart) polygon On line 46 the polygon is written to the output shapefile
import arcpy, os
from datetime import datetime
arcpy.env.overwriteOutput = True
# change path to datasource
fc = r"D:\Xander\GeoNet\MergePolsDate\Reserves_copy.shp"
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
# output shape
fc_out = r"D:\Xander\GeoNet\MergePolsDate\Reserves_merged.shp"
# 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)
flds = ("SHAPE@", fld_start, fld_end)
# 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)) 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]
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
# TODO: manage attributes
curs_out.insertRow((polygon, row[1], row[1]))
In case of any doubts, just post a reply. Kind regards, Xander
... View more
08-13-2014
11:58 AM
|
0
|
16
|
3642
|
|
POST
|
ZIP the extract of your data (shapefile or FGBD), and use the "reply" option in this thread. In the editor in the upper right corner you will see a link "Use advanced editor", once in the advanced editor you will see in the lower right corner the possibility to attach a file.
... View more
08-13-2014
08:32 AM
|
0
|
18
|
3642
|
|
POST
|
There is a point I don't really get; when the end date of a record (current date you want to process) is not equal to 2300, BUT it is higher than the current date, should it be removed from the output? It seems more logic to me if for each unique date in the StartDate you use all the records for which the start date is before the current date and the end date is after the current date and use those records to create the polygon. Anyway, I would probably use some Python code to: create a unique sorted list of start dates create a layer through the select by attributes dissolve the polygons and create a new featureclass (or add it to an existing one if you want the new merged polygons to be stored in 1 featureclass) Then there is still the issue of what to do with the attributes of the records you're merging... If you're willing to post a piece of your data, I can have a look and see what code is needed. Kind regards, Xander
... View more
08-12-2014
11:43 AM
|
0
|
20
|
3642
|
| 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
|