|
POST
|
I need to determine the shortest distance between each point within a single feature class. Near Analysis would have worked perfectly, but unfortunately you need to have an Advanced ArcGIS Licence and I only have a Standard Licence. I found the following code on Stack Exchange written by PolyGeo: import arcpy,math
# Set variables for input point feature classes and output table
ptFC1 = "C:/temp/test.gdb/PointFC1"
ptFC2 = "C:/temp/test.gdb/PointFC2"
outGDB = "C:/temp/test.gdb"
outTableName = "outTable"
outTable = outGDB + "/" + outTableName
arcpy.env.overwriteOutput = True
# Create empty output table
arcpy.CreateTable_management(outGDB,outTableName)
arcpy.AddField_management(outTable,"INPUT_FID","LONG")
arcpy.AddField_management(outTable,"NEAR_FID","LONG")
arcpy.AddField_management(outTable,"DISTANCE","DOUBLE")
# Create and populate two dictionaries with X and Y coordinates for each
# OBJECTID in second feature class using a SearchCursor
ptFC2XCoordDict = {}
ptFC2YCoordDict = {}
with arcpy.da.SearchCursor(ptFC2,["OBJECTID","SHAPE@XY"]) as cursor:
for row in cursor:
ptFC2XCoordDict[row[0]] = row[1][0]
ptFC2YCoordDict[row[0]] = row[1][1]
# Open an InsertCursor ready to have rows written for each pair of OBJECTIDs
iCursor = arcpy.da.InsertCursor(outTable,["INPUT_FID","NEAR_FID","DISTANCE"])
# Use a SearchCursor to read the rows (and X,Y coordinates) of the first
# feature class
with arcpy.da.SearchCursor(ptFC1,["OBJECTID","SHAPE@XY"]) as cursor:
for row in cursor:
x1 = row[1][0]
y1 = row[1][1]
for i in range(len(ptFC2XCoordDict)):
x2 = ptFC2XCoordDict[i+1]
y2 = ptFC2YCoordDict[i+1]
# Prepare and insert the InsertCursor row
iRow = [row[0],i+1,math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))]
iCursor.insertRow(iRow)
del iCursor
print "Done!" The following reports the distance of the first point to the rest of the points: I would like to amend the following to iterate through each point within the feature class to report the shortest distance between the points, greater than zero of course. Any advice in amending the following will be appreciated. I'm trying to use the results from this as a way of validating that none of the points are within 3m or less from each other and if there are the filtered list is processed further to move the points away from each other within bounding box for each point.
... View more
04-16-2016
09:07 AM
|
0
|
7
|
8366
|
|
POST
|
I would like some advise from the community that has experience within Geostatistical Analysis and in particular Kriging and Cokriging. I'm fairly new to GeoStatistics and Kriging and would like in advice in creating a MAP (Mean Annual Precipiation) surface from recorded MAP for rain stations within my study area. The following is my current parameters based on using the Kriging Tool within Spatial Analyst: in_point_features = rain stations z_field = MAP KrigingModelOrdinary: SemivariogramType = Exponential lagSize = default majorRange = default partialSill = default nugget = default cell_size = same a study area DSM (HydroSHEDS SRTM 90m DSM) search_radius = RadiusVariable(12) out_variance_predication_raster = None out_surface_raster = MAP_Kriging If I adjust the cell_size to match that of the study area DSM as well as the lagSize as the default is the output raster cell size it fails with the following error 010079. The error message recommends that: "By increasing the cell size, you will increase the number of sample points per cell size interval, thereby providing enough data points to estimate the semivariogram. Once the semivariogram is estimated, a smaller cell size can be used in creating the actual output raster" I'm not sure how one can achieve the following as the following is a single process, the estimation of the semivariogram is not a separate from the kriging. If someone can explain to me how to achieve the following it would be appreciated. My ultimate goal is to use the Geostatistical Analyst Cokriging to generate the MAP using the rain stations and the hydroSHEDS DSM as a second variable, based on the approach described by P.Goovaerts: Geostatistical approaches for incorporating elevation into the spatial interpolation of rainfall. If anyone has applied the following approach using the Geostatistical Analyst Cokriging help in setting the following would appreciated.
... View more
04-13-2016
03:41 PM
|
0
|
1
|
4655
|
|
POST
|
Hi Rodrigo If the contours file is not too large zip it and attach it to the forum postl. I'll have a look at the following to see if I can resolve the problem that you are having, Regards Peter
... View more
04-11-2016
07:59 AM
|
0
|
2
|
3827
|
|
POST
|
I've briefly had a look at your code and have made a few changes. If you could attach a sample of your input data that you are reading from as well as the template Feature Class I'd be able to help you more. Also attach a print screen of the error message that you are receiving. # import site-packages and modules
import arcpy
import os
# set arguments
outputFC = arcpy.GetParameterAsText(0)
fClassTemplate = arcpy.GetParameterAsText(1)
f = open(arcpy.GetParameterAsText(2),'r')
# set environment settings
arcpy.env.overwriteOutput = True
try:
output_path = os.path.split(outputFC)[0]
output_name = os.path.split(outputFC)[1]
arcpy.CreateFeatureclass_management(output_path, output_name, "point", fClassTemplate)
lstFires = f.readlines()
cur = arcpy.InsertCursor(outputFC)
cntr = 1
for fire in lstFires:
if 'Latitude' in fire:
continue
vals = fire.split(",")
latitude = float(vals[0])
longitude = float(vals[1])
confid = int(vals[2])
pnt = arcpy.Point(longitude, latitude)
feat = cur.newRow()
feat.shape = pnt
feat.setValue("CONFIDENCEVALUE", confid)
cur.insertRow(feat)
arcpy.AddMessage("Record number: " + str(cntr) + " written to feature class")
cntr = cntr + 1
except:
print arcpy.GetMessages()
finally:
del cur
f.close()
... View more
04-10-2016
01:09 AM
|
1
|
0
|
1037
|
|
POST
|
Hi Rodrigo I suspect its the environment settings that are not being explicitly being set when you run the TopoToRaster from Python. When you run it from within ArcMap your current environment settings would be used. I also noted that you have not provided a Boundary Feature Class or set the output Cell Size of the DEM that you are generating. I would try to first provide a boundary Feature Class to limit the DEM extent that is being generated. Make sure they are both using same projected coordinate system. I run TopoTo Raster on a daily basis on very large data sets that few would ever require and using the following workflow have had no errors: Dissolve my contours by the height field (Make sure to remove the selection to create multi-parts) Repair the geometry of the dissolved contours to remove any empty or self intersecting geometries Provide a Boundary Feature Class to limit the extent of the processing extent Provide a Cell Size for the output DEM based on the limitations of the input contours. As a rule of thumb I don't exceed the contour height interval by half. (.i.e. Contour vertical interval is 10m so my Cell Size would be 5m) Hope the following helps
... View more
04-10-2016
12:43 AM
|
0
|
4
|
3827
|
|
POST
|
Thanks Dan Will definitely keep you posted, thanks again for all the help, Peter
... View more
04-09-2016
02:32 PM
|
0
|
0
|
731
|
|
POST
|
Hi Dan Based on reading up on Numpy and Pandas I have come up with the following. The following is still work in progress based on my initial understanding of Numpy Arrays and Pandas DataFrames: '''
Created on April 6, 2016
Summarise
Number of Buildings
per Time Interval
(5, 10, 15, 25, 30, 60)
@author: PeterW
'''
# import site-packages and modules
from pathlib import Path
import numpy.lib.recfunctions as rfn
import pandas as pd # Pandas version 0.13.0
import arcpy
# set arguments
saa_stats_table = r"E:\Python\Testing\Numpy_Pivot_Table\Input_Data.gdb\Alma_Clinic_Sum"
# environment settings
arcpy.env.overwriteOutput = True
fgdb = Path(saa_stats_table).parents[0]
def pivot_table(saa_stats_table, fgdb):
fields = [f.name for f in arcpy.ListFields(saa_stats_table)]
table_recarray = arcpy.da.TableToNumPyArray(saa_stats_table, fields) # @UndefinedVariable
df = pd.DataFrame(table_recarray[fields])
pivot = df.pivot(index="OBJECTID",
columns="TIME",
values="FREQUENCY").fillna(0, downcast="infer")
pivot_fields = pivot.columns.values
# rename pivot fields with prefix "TIME"
pivot.columns = [("{0}{1}".format("TIME", field)) for field in pivot_fields]
# convert pandas dataframe to record array
pivot_recarray = pivot.to_records(index=False)
pivot_type = pivot_recarray.dtype.descr
pivot_type_new = [(x[0], x[1].replace(x[1], "<i2")) for x in pivot_type]
# change pivot record array data type to short integer
pivot_recarray = pivot_recarray.astype(pivot_type_new)
fields2 = ["TOWN", "SETTLEMENTNAME", "NAME"]
table_type_new = [(str(x), "<U25") for x in fields2]
# change table array data type to unicode 50 characters
table_recarray = table_recarray[fields2].astype(table_type_new)
recarray_list = [table_recarray, pivot_recarray]
# merge table and pivot record array
summary_array = rfn.merge_arrays(recarray_list, flatten=True, usemask=False)
summary_table = str(Path(fgdb, "SAA_Stats"))
# convert merged record array to file geodatabase table
if arcpy.Exists(summary_table):
arcpy.Delete_management(summary_table)
arcpy.da.NumPyArrayToTable(summary_array, summary_table) # @UndefinedVariable
else:
arcpy.da.NumPyArrayToTable(summary_array, summary_table) # @UndefinedVariable
pivot_table(saa_stats_table, fgdb) Summary Table: Field Properties Summary Table: Results I'm currently reading through the documentation that you have supplied and will get back to you once I've read the python reference documentation to better understand how the following works.
... View more
04-09-2016
02:15 PM
|
0
|
0
|
2481
|
|
POST
|
Hi Darren I'm getting the following error message, not sure if its because I'm still using ArcGIS 10.2.2 and Python 2.7.5
... View more
04-04-2016
02:36 PM
|
0
|
2
|
2481
|
|
POST
|
Hi Daren Can I ask that you re-post your code with the indentation corrected as I tried regenerating your code but most likely have the indentation incorrect and receiving error messages. Thanks in advance.
... View more
04-04-2016
01:56 PM
|
0
|
4
|
2481
|
|
POST
|
Hi Dan Thanks for the following. I'm going to go through the following over the weekend. I'll post my final code on Monday so that anyone else trying to achieve solving a similar problem can use it as a starting point. Thanks once again for all the help.
... View more
04-02-2016
12:23 AM
|
0
|
0
|
2481
|
|
POST
|
Hi Darren Thanks for the following looks great. I'm going to work on the following over the weekend. I'll post my final code on Monday for anyone else to use as a starting point, trying to achieve a similar result.
... View more
04-02-2016
12:14 AM
|
0
|
0
|
4671
|
|
POST
|
Hi Joshua, Thanks for the following suggestion. This would have gotten be a lot closer to what I was looking for. Unfortunately I only have a Standard Licence.
... View more
03-31-2016
01:08 PM
|
0
|
2
|
4671
|
|
POST
|
Hi Dan I've attached an Excel table based on the summary statistics table above, thanks once again for offering your assistance.
... View more
03-31-2016
12:57 PM
|
0
|
8
|
4671
|
|
POST
|
I originally posted the question under the following post: Python solution to convert single column into multiple columns but its seems I didn't explain clearly what I'm trying to achieve. I hope the following is a lot clearer as I desperately need to solve the following as I have few hundred table to process. I have generated summary statistics tables based on the results of an intersection. The summary statistics table format is as per below: if you look at the following table as an example: Mossel Bay, Asla Park B, Alma Clinic appears twice as there 6 buildings found within 20 minutes and 148 buildings within 25 minutes. I need to convert the table structure so that there is one entry for: Mossel Bay, Also Park B, Alma Clinic with the TIME field being split per interval (i.e. 5min, 10min - 60min) with the number of buildings (COUNT_NAME) being populated within the appropriate fields as per below: As you can see from the example above Mossel Bay, Asla Park B, Alma Clinic has a single row and the Number of buildings have been populated within the appropriate fields per time interval. I've tried using ArcPy Data Access Module with no success as the rows are not unique so insert cursor wont work, can't use the update cursor as I'm trying to populate an empty table. I was considering numpy, but would need some advice on how to get started and also considered python dictionaries and also realised my knowledge is limited at this stage. Any advice to solve the following would be appreciated.
... View more
03-31-2016
08:49 AM
|
1
|
21
|
16075
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | 01-16-2012 02:34 AM | |
| 1 | 05-07-2016 03:04 AM | |
| 1 | 04-10-2016 01:09 AM | |
| 1 | 03-13-2017 12:27 PM | |
| 1 | 02-17-2016 02:34 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-04-2021
12:50 PM
|