POST
|
Like Darren Wiens said, there are many ways. I'd use da.SearchCursor and for loop to iterate through each row in the conductor feature class and use an If/Else statement to determine if it the record is an OH or UG line. From there you can add the value in the Shape.Length field to keep a running sum of each. You could easily convert back and forth between feet and miles after that. For the water main feature class, the Summary Statistics tool would be good since you need total length only, not broken down into sub-categories. You can hardcode the variables in and once the python script is 100% correct, create a script tool in ArcCatalog that references the python script for a "one-click-button".
... View more
08-05-2016
01:56 PM
|
1
|
0
|
1101
|
POST
|
Thank you for the helpful comments. Turned out it was a subnet issue that our IT people were able to resolve.
... View more
03-16-2016
01:41 PM
|
0
|
1
|
506
|
POST
|
We get this error when attempting to run arccatalog and arcmap (see image attachment) on a virtual machine. We are pointing to a machine that houses the concurrent use license manager. The odd thing is that when running ArcGIS for desktop (Standard) 10.2 from a different VM that is pointing to the same license manager, we receive no errors. We can't figure out how to address the errors on the VM that has 10.3 installed. We have another machine (not a VM - but a standard laptop) that has 10.3 installed and is pointing to the same concurrent use license manager and it runs just fine. Any ideas?
... View more
03-14-2016
01:52 PM
|
0
|
4
|
3649
|
POST
|
Rather than creating brand new feature classes to run zonal stats, you could select each polygon individually and run zonal stats with it. Basic workflow would be: 1) create an index that will loop through each polygon in your fc, n=50 for example, that you want to calculate zonal stats in:
i=1
for i in range(50):
2) convert your polygon fc with UID=1 to feature layer.
polyLyr=arcpy.MakeFeatureLayer_management(polygonFC, outputLyr, "\"UID\"={}".format(str(i)))
3) select your new feature layer by attribute. THEN: 4) begin another for loop that will iterate through your raster grids. 5) calculate zonal stats within your selected polygon with each of your raster grids. 6) append the output zonal stats table however you'd like.
... View more
05-29-2014
03:48 PM
|
0
|
0
|
911
|
POST
|
I have a 9 year weekly time series (~500 raster grids of equal cell size and extent). I'm interested in obtaining the regression line slope between pixels (Imagine stacking all 500 grids on top of one another and running a linear regression between each individual pixel). Essentially, this would measure the net change between pixels through my time series. My main question is about the coefficients defined in the first answer here. Is the coefficient defined as 12 due to the temporal scale of the original question being at the monthly level? And if so, should my code's coefficient be set to 7 due to the weekly temporal scale between my grids? I have been referencing these posts that are similar: Representing trends over time: (http://gis.stackexchange.com/questions/65787/arcgis-make-linear-regression-across-multiple-raster-layers) Make linear regression across multiple layers: (http://gis.stackexchange.com/questions/52502/how-to-represent-trend-over-time?rq=1) I wrote this python code after reading the links referenced above:
from __future__ import division
import arcpy
import os
from arcpy import env
from arcpy.sa import*
# define workspace
arcpy.env.workspace=r"C:\Users\mbs7038\Documents\Remove_Gauge_Outliers\test\forSlope.gdb"
# enable overwriting
arcpy.env.overwriteOutput=True
# check spatial analyst extension
arcpy.CheckOutExtension('Spatial')
# define output paths
slopePath=r"C:\Users\mbs7038\Documents\Remove_Gauge_Outliers\SpatialTrends\SlopeTEST.gdb"
# list all rasters in the workspace
rasters=arcpy.ListRasters('*')
# sort rasters numerically
rasters.sort()
# get the number of rasters
n=len(rasters)
print n
# setup index
i=1
# define division
seed=(n*n*n)-n
print 'the global seed is {0}'.format(seed)
for raster in rasters:
print i
coef=(12*(i)-((6*n)+(6*1)))/seed
print 'Raster {0} is {1}:'.format(i,raster)
print 'the coef for raster {0} is {1}'.format(i,coef)
# Multiply raster by coefficient and add to output slope grid
if i==1:
outSlope=(Raster(raster)*coef)
i+=1 # same as saying i=i+1
else:
print 'adding {0} to outSlope'.format(raster)
outSlope=outSlope+(Raster(raster)*coef)
i+=1
if i==6:
break
# Save final slope grid
print 'saving final slope grid'
outSlope.save(slopePath + "/" + "floodChange_py")
print 'script is complete'
I created this code as a test which appeared to work on a 5 week subset of my data. If what I have referenced above is correct then this code will work on a time series (of equal cell size and extent) of any length. Although there were no bugs in the code, I have a feeling I may have made a mistake someplace and would appreciate extra eyes on my code. Any advice or recommendations? On a side note I'm using PyScripter, hence the "from future import division" in the first line. This disables the automatic floor function which rounds floating point numbers to the nearest integer away from zero.
... View more
05-26-2014
03:02 PM
|
0
|
0
|
3202
|
POST
|
Thanks for the info Steve. I'll definitely keep this is mind. Ben
... View more
05-26-2014
02:45 PM
|
0
|
0
|
530
|
POST
|
Interesting....Thanks for the info. Must have missed that when I was reading up on all things geostatistical analyst. I'll give it a go.
... View more
04-24-2014
09:36 AM
|
0
|
0
|
530
|
POST
|
I'm trying to loop through feature classes and create a geostatistical layer and then convert the geo layer to points. I've attempted to debug this problem myself, but would appreciate extra eyes on my code in case someone else can spot an error. Here is a resource that I've referenced trying to fix my code: http://forums.arcgis.com/threads/92508-Need-Help-Automation-of-Kriging-using-Model-builder-or-python-Reg import arcpy from arcpy import env from arcpy.sa import* from arcpy.ga import* arcpy.env.workspace = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb" arcpy.env.overwriteOutput=True lyrpath = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_lyrs" ptpath="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_Krig.gdb" # Check out the ArcGIS Geostatistical Analyst extension license arcpy.CheckOutExtension("GeoStats") #modelTemplate="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_Model.lyr" modelxml=("C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\EmpiricalBayesianKriging.xml") print 'listing feature classes' fcs=arcpy.ListFeatureClasses("a734184") for fc in fcs: print fc try: print 'listing fields' fields = arcpy.ListFields(fc,"Wlevel") for field in fields: print ("{0} is a type of {1} with a length of {2}".format(field.name, field.type, field.length)) zfield="Wlevel" outlyr=lyrpath+"/"+fc+"_GA.lyr" outpts=ptpath+"/"+fc+"_GA_pt" #cellsize=0.0008333333333 print'creating geostatistical layer' infc=fc + " Wlevel" arcpy.GACreateGeostatisticalLayer_ga(modelxml,infc,outlyr) print 'converting GA layer to grid' arcpy.GALayerToPoints_ga(outlyr,fc,zfield,outpts) except: print arcpy.GetMessages() print 'script complete' I receive these error messages: a734184_GA.lyr does not exist or is not supported I've checked my output folder that I've defined to store the new geostat layers, and there is nothing there, even though I received no error messages when running the CreateGeostatisticalLayer tool...... >>> listing feature classes a734184 listing fields Wlevel is a type of Double with a length of 8 creating geostatistical layer converting GA layer to grid Executing: GALayerToPoints C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_lyrs/a734184_GA.lyr C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb\a734184 Wlevel C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_Krig.gdb\a734184_GA_pt ALL Start Time: Thu Apr 24 12:12:05 2014 Failed to execute. Parameters are not valid. ERROR 000732: Input geostatistical layer: Dataset C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_lyrs/a734184_GA.lyr does not exist or is not supported Failed to execute (GALayerToPoints). Failed at Thu Apr 24 12:12:05 2014 (Elapsed Time: 0.00 seconds) script complete >>>
... View more
04-24-2014
08:24 AM
|
0
|
1
|
609
|
POST
|
I'm trying to loop through feature classes and create a geostatistical layer and then convert the geo layer to points. I've attempted to debug this problem myself, but would appreciate extra eyes on my code in case someone else can spot an error. Here is a resource that I've referenced trying to fix my code: http://forums.arcgis.com/threads/92508-Need-Help-Automation-of-Kriging-using-Model-builder-or-python-Reg import arcpy from arcpy import env from arcpy.sa import* from arcpy.ga import* arcpy.env.workspace = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb" arcpy.env.overwriteOutput=True lyrpath = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_lyrs" ptpath="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_Krig.gdb" # Check out the ArcGIS Geostatistical Analyst extension license arcpy.CheckOutExtension("GeoStats") #modelTemplate="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_Model.lyr" modelxml=("C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\EmpiricalBayesianKriging.xml") print 'listing feature classes' fcs=arcpy.ListFeatureClasses("a734184") for fc in fcs: print fc try: print 'listing fields' fields = arcpy.ListFields(fc,"Wlevel") for field in fields: print ("{0} is a type of {1} with a length of {2}".format(field.name, field.type, field.length)) zfield="Wlevel" outlyr=lyrpath+"/"+fc+"_GA.lyr" outpts=ptpath+"/"+fc+"_GA_pt" #cellsize=0.0008333333333 print'creating geostatistical layer' infc=fc + " Wlevel" arcpy.GACreateGeostatisticalLayer_ga(modelxml,infc,outlyr) print 'converting GA layer to grid' arcpy.GALayerToPoints_ga(outlyr,fc,zfield,outpts) except: print arcpy.GetMessages() print 'script complete' I receive these error messages: a734184_GA.lyr does not exist or is not supported I've checked my output folder that I've defined to store the new geostat layers, and there is nothing there, even though I received no error messages when running the CreateGeostatisticalLayer tool...... >>> listing feature classes a734184 listing fields Wlevel is a type of Double with a length of 8 creating geostatistical layer converting GA layer to grid Executing: GALayerToPoints C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_lyrs/a734184_GA.lyr C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb\a734184 Wlevel C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_Krig.gdb\a734184_GA_pt ALL Start Time: Thu Apr 24 12:12:05 2014 Failed to execute. Parameters are not valid. ERROR 000732: Input geostatistical layer: Dataset C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\GA_lyrs/a734184_GA.lyr does not exist or is not supported Failed to execute (GALayerToPoints). Failed at Thu Apr 24 12:12:05 2014 (Elapsed Time: 0.00 seconds) script complete >>>
... View more
04-24-2014
08:21 AM
|
0
|
4
|
3716
|
POST
|
The same issues keep happening with my code. Here is the code I'm working with:
import arcpy
from arcpy import env
from arcpy.sa import*
arcpy.env.workspace=r"C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\Sylhet_Gauges\Sylhet_Gauges.gdb"
env.overwriteOutput=True
arcpy.env.overwriteOutput=True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
krigpath= "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\Sylhet_Gauges\Krig4MinDiff.gdb"
maskpath= "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Minimize_DEM_Analysis\Mask4MinDiff.gdb"
print 'listing feature classes'
fcs=arcpy.ListFeatureClasses("a*")
bounds="Sylhet_BasinBoundary"
print 'beginning fc for loop'
for fc in fcs:
print fc
try:
zfield = "Wlevel"
savekrig = krigpath +"/" + "Syhlet_" + fc
savemask = maskpath +"/" + "Sylhet_" + fc
print ('kriging {0}'.format(fc))
outKrig=arcpy.sa.Kriging(fc,zfield,KrigingModelOrdinary ("Spherical",0.0008333333333),0.0008333333333)
outKrig.save(savekrig)
print ('extracting {0} by {1}').format(fc,bounds)
outmask=arcpy.sa.ExtractByMask(saveKrig,bounds)
outMask.save(savemask)
except:
print arcpy.GetMessages()
print 'script complete'
This code works sometimes and completes a few iterations and then fails at the kriging step with this error message:
Executing: Kriging C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\Sylhet_Gauges\Sylhet_Gauges.gdb\a733547 Wlevel C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\Sylhet_Gauges\Sylhet_Gauges.gdb\Kriging_a7331 "Spherical 0.000833" 0.0008333333333 "VARIABLE 12" #
Start Time: Thu Apr 03 13:57:44 2014
ERROR 999999: Error executing function.
Workspace or data source is read only.
Workspace or data source is read only.
The operation was attempted on an empty geometry.
ERROR 010029: Unable to create the raster __1000000.
Failed to execute (Kriging).
Failed at Thu Apr 03 13:57:45 2014 (Elapsed Time: 1.00 seconds)
or the extraction step with the same error message:
extracting a732847
Executing: ExtractByMask C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\krig4MinDiff.gdb/SW_a732847 by C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundaryC:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundary C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\Extract_SW_a2
Start Time: Thu Apr 03 13:23:31 2014
ERROR 999999: Error executing function.
Workspace or data source is read only.
Workspace or data source is read only.
The operation was attempted on an empty geometry.
ERROR 010302: Unable to create the output raster: C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\Extract_SW_a2
ERROR 010067: Error in executing grid expression.
Failed to execute (ExtractByMask).
In both cases, the grid is called that was saved by default, even though I call the grids that were just supposedly saved using the .save() function. My guess is that these default grids are read only and do not have defined geometry? hence these error messages? I'm stumped.
... View more
04-03-2014
10:27 AM
|
0
|
0
|
690
|
POST
|
I've returned back to this script to use it again and unfortunately the same error message as before keeps occurring.
extracting a732847
Executing: ExtractByMask C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\krig4MinDiff.gdb/SW_a732847 by C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundaryC:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundary C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\Extract_SW_a2
Start Time: Thu Apr 03 13:23:31 2014
ERROR 999999: Error executing function.
Workspace or data source is read only.
Workspace or data source is read only.
The operation was attempted on an empty geometry.
ERROR 010302: Unable to create the output raster: C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\Extract_SW_a2
ERROR 010067: Error in executing grid expression.
Failed to execute (ExtractByMask).
Failed at Thu Apr 03 13:23:32 2014 (Elapsed Time: 1.00 seconds)
script complete
Here is the code with the suggestions you have made:
import arcpy
from arcpy import env
from arcpy.sa import*
arcpy.env.workspace=r"C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb"
env.overwriteOutput=True
arcpy.env.overwriteOutput=True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
krigpath= "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\krig4MinDiff.gdb"
maskpath= "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Minimize_DEM_Analysis\Mask4MinDiff.gdb"
print 'listing feature classes'
fcs=arcpy.ListFeatureClasses("a732847*")
bounds="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundary"
print 'beginning fc for loop'
for fc in fcs:
print fc
try:
zfield = "Wlevel"
savekrig = krigpath +"/" + "SW_" + fc
savemask = maskpath +"/" + "SW_" + fc
print ('kriging {0}'.format(fc))
outKrig=arcpy.sa.Kriging(fc,zfield,KrigingModelOrdinary ("Spherical",0.0008333333333),0.0008333333333)
outKrig.save(savekrig)
print ('extracting {0} by {1}').format(fc,bounds)
outMask=arcpy.sa.ExtractByMask(savekrig,bounds)
outMask.save(savemask)
except:
print arcpy.GetMessages()
print 'script complete'
Any other possible ideas as to why I keep getting these errors? I'm stumped as to why the computer attempts to use the grids that are saved by default ("Extract_SW_a2" in the error code block) for the functions in the loop when I specifically call for the grid that was just saved (savekrig). All grids that I call for in the loop have defined coordinate systems and are not opened in arcmap, arccatalog, or any other program.... I think the default grids that get created and used in the functions are what's causing these errors. But Why?
... View more
04-03-2014
09:48 AM
|
0
|
0
|
678
|
POST
|
when you saved the intermediate rasters, did you call them in the next function?
.save(intermediate_file)
outextractbymask=(intermediate_file,mask)
... View more
03-26-2014
02:16 PM
|
0
|
0
|
1354
|
POST
|
I'm experiencing the same issue using the .save() after extracting by mask within a for loop. The output grid is being saved in my env.workspace with default naming parameters. Can you elaborate on when you "put a full directory to where it was being saved" which fixed it?
... View more
03-25-2014
10:54 AM
|
0
|
0
|
690
|
Title | Kudos | Posted |
---|---|---|
1 | 05-30-2014 08:06 AM | |
1 | 08-05-2016 01:56 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|