POST
|
I'm still having the same issue even with the code snippet that you just posted. This is the code I created. #import arcpy and arcview library; overwrite any previous output
import arcpy
import arcview
arcpy.env.overwriteOutput = True
#set workspace to GetParameter field
#myWorkspace = arcpy.GetParameterAsText(0)
myWorkspace = r'X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\January2017\SaltLakeCity_Projections'
arcpy.env.workspace = myWorkspace
print myWorkspace
print arcpy.env.workspace
#acquire extensions for Business Analyst and Network Analyst for use
arcpy.CheckOutExtension("Business")
arcpy.CheckOutExtension("Network")
#set the spatial reference; 4269 is code for GCS_North_American_1983
spatialRef = arcpy.SpatialReference(4269)
#in order to use its tools, add Business Analyst toolbox to script
arcpy.AddToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.4\Business Analyst\ArcToolbox\Toolboxes\Business Analyst Tools.tbx")
#create GetParameter for input csv table that has store location and lat/long
##inputTable = arcpy.GetParameterAsText(1)
inputTable = r"X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\January2017\SaltLakeCity_Projections\SaltLakeCity_latLong.csv"
###set variables for lat/long table
##location = "Location"
##xCoord = "Long"
##yCoord = "Lat"
##outlayer = "LocationXY"
#create cursor to access csv table;
cursor = arcpy.SearchCursor(inputTable)
for row in cursor:
location = row.getValue('Location')
xCoord = row.getValue('Long')
yCoord = row.getValue('Lat')
print location
print xCoord
print yCoord In rows, 33-41, I'm trying to create the cursor to read the CSV table. My print statements show that the location I'm printing is still just the last row of the table. Here's my print statements. X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\January2017\SaltLakeCity_Projections X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\January2017\SaltLakeCity_Projections Heber_1200_SouthMain -111.413542 40.492089 How do I go through and create a variable for each location (row)? And then how would I run analysis on each of those locations?
... View more
01-24-2017
01:00 PM
|
0
|
1
|
840
|
POST
|
What I'm struggling with is how to create different locations/feature classes from the CSV table, and then have the script go through the above bullet-list process for each of those stores. So I wrote this script to access the input table with a cursor. But two issues: I'm not sure if that's the proper way to use the cursor function for this process. Even if it is, how do I then name each of those rows (locations) in a way to be able to run the process on all 10, 50, whatever number of locations there are? #create cursor to access csv table;
cursor = arcpy.SearchCursor(inputTable)
for row in cursor:
location = row.Location
xCoord = row.Long
yCoord = row.Lat
print location
print xCoord
print yCoord
... View more
01-23-2017
02:45 PM
|
0
|
2
|
840
|
POST
|
I've set up an arcpy script that does the following things after the user selects a workspace and a CSV file through a couple Get Parameter as Text options in ArcMap: Creates an XY data file based on data in the CSV file Creates 3 different buffers on that point file Creates 3 different drive time trade areas on that point file Does a spatial append on those buffer files and the drive time files Pull nearby competition within the drive time areas Creates and exports that data to an Excel table Here is the script. #import arcpy and arcview library; overwrite any previous output
import arcpy
import arcview
arcpy.env.overwriteOutput = True
#set workspace to GetParameter field
myWorkspace = arcpy.GetParameterAsText(0)
arcpy.env.workspace = myWorkspace
print myWorkspace
print arcpy.env.workspace
#acquire extensions for Business Analyst and Network Analyst for use
arcpy.CheckOutExtension("BusinessPrem")
arcpy.CheckOutExtension("Network")
#set the spatial reference; 4269 is code for GCS_North_American_1983
spatialRef = arcpy.SpatialReference(4269)
#in order to use its tools, add Business Analyst toolbox to script
arcpy.AddToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.3\Business Analyst\ArcToolbox\Toolboxes\Business Analyst Tools.tbx")
#create GetParameter for input csv table that has store location and lat/long
inputTable = arcpy.GetParameterAsText(1)
#assign variables for input table
xCoord = "Long"
yCoord = "Lat"
outLayer = "LocationXY_"
#create XY layer for location
arcpy.MakeXYEventLayer_management(inputTable, xCoord, yCoord, outLayer, spatialRef)
print(arcpy.GetCount_management(outLayer))
#create cursor to access csv table; acquire name of site location
cursor = arcpy.SearchCursor(outLayer)
for row in cursor:
location = row.Location
print location
#create file geodatabase for site's spatial data
folderPath = myWorkspace
geoDBname = "{0}.gdb".format(location)
print geoDBname
arcpy.CreateFileGDB_management(folderPath, geoDBname)
arcpy.env.workspace = geoDBname
print myWorkspace
print arcpy.env.workspace
#create layer name for converting XY layer to feature class data
fcLocation = outLayer + location
print fcLocation
arcpy.CopyFeatures_management(outLayer, fcLocation)
print ("FC Conv Done")
#create layer name for buffer data
#perform multi-ring buffer analysis on location
bufferString = "Buffer_"
fcBuffer = bufferString + fcLocation
arcpy.MultipleRingBuffer_analysis(fcLocation, fcBuffer, [0.5, 1, 3], "Miles",)
print ("Buff Done")
#create layer name for drive time data
#perform drive time analysis on location
driveTimeString = "DriveTime_"
fcDriveTime = driveTimeString + fcLocation
arcpy.DriveTime_ba(fcLocation, "Location", "All", "2.5; 5; 10", "Minutes", fcDriveTime)
print ("DT Done")
#Create variables for spatial overlay function
inputLayer = "C:\ArcGIS\Business Analyst\US_2015\Data\Demographic Data\esri_bg.bds"
demogFields = "INDMGMT_CY; A25I25_CY; A35I150_CY; A45I75_CY; MEDIA55_CY; \
MEDDIA35CY; A15NW250CY; AVGNWA65CY; MEDVAL_CY; POPGRWCYFY; \
N14_EMP; N17_BUS; N18_BUS; N34_EMP"
#create layer name for buffer append; append spatial data to buffers
bufferAppendString = "BufferAppend_"
fcBufferAppend = bufferAppendString + fcLocation
arcpy.SpatialOverlay_ba(inputLayer, fcBuffer, demogFields, fcBufferAppend)
print ("Buff Append Done")
#create layer name for drive time append; append spatial data to drive time
driveTimeAppendString = "DriveTimeAppend_"
fcDriveTimeAppend = driveTimeAppendString + fcLocation
arcpy.SpatialOverlay_ba(inputLayer, fcDriveTime, demogFields, fcDriveTimeAppend)
print ("DT Append Done")
#create layer name for buffer table export; export buffer data to Excel
#change workspace back to folder for Excel data
excelExtension = ".xls"
bufferAppendExcelString = "BufferAppendTable_"
bufferAppendTable = myWorkspace + "/" + bufferAppendExcelString + fcLocation + excelExtension
arcpy.TableToExcel_conversion(fcBufferAppend, bufferAppendTable)
print ("Buffer Table Done")
#create layer name for drive time export; export drive time data to Excel
driveTimeAppendExcelString = "DriveTimeAppendTable_"
driveTimeAppendTable = myWorkspace + "/" + driveTimeAppendExcelString + fcLocation + excelExtension
arcpy.TableToExcel_conversion(fcDriveTimeAppend, driveTimeAppendTable)
print ("Drive Time Table Done")
#create layers for summarize within function; pull number of c-stores within drive time polygon
joinSpatialConvStores = r'Y:\BI\KalibrateCompLoc\KGCompAllMarkets_Aug2016.shp'
targetFeaturePoly = fcDriveTimeAppend
businessPointsString = "CStoreCount_"
outPolyCStorePoints = businessPointsString + fcLocation
arcpy.SpatialJoin_analysis(targetFeaturePoly, joinSpatialConvStores, outPolyCStorePoints)
print ("CStore Count Done")
#create layer name for c-store count export; export c-store count to Excel
convStoreCountString = "CStoreCountTable_"
convStoreCountTable = myWorkspace + "/" + convStoreCountString + fcLocation + excelExtension
arcpy.TableToExcel_conversion(outPolyCStorePoints, convStoreCountTable)
print ("CStore Table Done")
#return Business Analyst and Network Analyst extensions
arcpy.CheckInExtension("BusinessPrem")
arcpy.CheckInExtension("Network")
print ("FINISHED") The point of this script is to run a site through ESRI in order to get all of the key demographic and competition data for a potential location in order to run through a regression model that we use to predict success. At this point in time, we can only run a CSV file that has one row (location) through the Python tool. What I want to do is update the script to be iterative and be able to run multiple rows (locations) through the tool at once. Any thoughts on easy changes to make this possible? I've made a few attempts at this and have encountered quite a few errors. I can upload that script if people would like to see what I've tried.
... View more
01-23-2017
01:30 PM
|
0
|
6
|
1724
|
POST
|
Can you say a bit more on this? Isn't the feature layer/shapefile that's selected in the GetParameter dialog box just a file path to the shapefile? Or is it read a different way?
... View more
08-30-2016
01:52 PM
|
0
|
1
|
415
|
POST
|
Okay, that makes sense and I've set up my GetParameters with the proper setup and with the correct order. However, still having an issue with that final GetParameter running as an error message. Here's the code. Line 3 is what I'm putting as the parameter in line 2, and it's failing. However, if I remove the comment from line 3 and run the script that way with no final GetParameter, it's still running fine. #create layers for summarize within function; pull number of c-stores within drive time polygon
joinSpatialConvStores = arcpy.GetParameter(2)
#joinSpatialConvStores = r"Y:\BI\KalibrateCompetitionLocations\MPSICompetitionLocations\2015Surveys\DesMoines_2015_locations.shp"
targetFeaturePoly = fcDriveTimeAppend
businessPointsString = "CStoreCount_"
outPolyCStorePoints = businessPointsString + fcLocation
arcpy.SpatialJoin_analysis(targetFeaturePoly, joinSpatialConvStores, outPolyCStorePoints)
print ("CStore Count Done")
... View more
08-30-2016
12:08 PM
|
0
|
3
|
415
|
POST
|
I thought that would work, but sadly, it did not. Received the same error message. One question I did have, would I change GetParameterAsText(2) to GetParameter(0) or GetParameter(2)? It would still be the third parameter in total in the script, but it would be the first parameter defined by the GetParameter function (no AsText)? Any other thoughts?
... View more
08-30-2016
10:19 AM
|
0
|
6
|
1140
|
POST
|
I've corrected all the file paths to remove any perceived spaces, and the issue is still occurring. I don't think that was the issue as the other two GetParameter's were also pathed in similar ways. The script still works when I directly write the code linking to the file path (spaces or no spaces); it's only when I try to use a GetParameterAsText when it does not.
... View more
08-30-2016
09:55 AM
|
0
|
0
|
1140
|
POST
|
The paths for the first two parameters are as follows, and they work perfectly. X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\August2016\DesMoines.Hickman86th X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\August2016\DesMoines.Hickman86th\DesMoines_Hickman_86th.csv
... View more
08-30-2016
09:40 AM
|
0
|
1
|
1140
|
POST
|
Can folder names in file paths not even include underscores? Because that's what my folder path has; there are no "true" spaces.
... View more
08-30-2016
09:36 AM
|
0
|
2
|
1140
|
POST
|
I'm attempting to write code to run a buffer and drive time analysis on an XY data file and then count features from another shapefile within the drive time trade area that's created. I'm attempting to use the Spatial Join (Analysis) for the latter process. I'm currently having an error with my code at the Spatial Join part of the code. It says the dataset "false" does not exist, which is not a dataset that I'm trying to use or am even aware of. Here is the error message with the key details: Traceback (most recent call last): File "Y:\BI\GIS Data\GIS Data Backup\Python Scripts\InternalModel_PythonScript_SingleSite.py", line 121, in <module> arcpy.SpatialJoin_analysis(targetFeaturePoly, joinSpatialConvStores, outPolyCStorePoints) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\analysis.py", line 471, in SpatialJoin raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Join Features: Dataset false does not exist or is not supported Failed to execute (SpatialJoin). I will say, this script runs properly when I do not see the final parameter, but instead link directly to the file path in the code. It's once I try to use GetParameterAsText when the error occurs. Here is the code attached. The error is occurring in this section. When I remove the comment from line 3 and run the script directly setting that variable to the shapefile, it works fine. #create layers for summarize within function; pull number of c-stores within drive time polygon
joinSpatialConvStores = arcpy.GetParameterAsText(2)
#joinSpatialConvStores = r"X:\Users\Andy.Rowlands\AHR.Data\MPSI_KalibrateData\MPSI_Competition_Locations\2015Surveys\DesMoines_2015_locations.shp"
targetFeaturePoly = fcDriveTimeAppend
businessPointsString = "CStoreCount_"
outPolyCStorePoints = businessPointsString + fcLocation
arcpy.SpatialJoin_analysis(targetFeaturePoly, joinSpatialConvStores, outPolyCStorePoints)
print ("CStore Count Done")
... View more
08-30-2016
09:30 AM
|
0
|
15
|
2743
|
POST
|
Is there any good reason why the data update did not include the Total Employees data? Even if they couldn't update it, why didn't they just carry over the old Employee data? I've gone back and forth between the new Business Analyst and the old one trying to pull all of the employee data I need, and it's been a real issue and nuisance to continually install and un-install things. Any solution out there?
... View more
06-29-2012
02:04 PM
|
0
|
1
|
1418
|
POST
|
This is a tough one, because it is hard to determine how the employee numbers are distributed throughout the grid polygon (i.e. are they spread equally across the polygon, are should some areas of the polygon be weighted differently than others?). Off the top of my head, the only thing that comes to mind is creating a custom BDS layer in the Business Analyst Desktop extension. You would use the Custom Data Setup Tool and select the proper apportionment method. You could then create your trade areas of 1 mile buffers around your cities and use the Spatial Overlay (Append) tool to grab the values from the Grid. Then, depending on what apportionment settings you have set up in BA, you should see different numbers. The Advanced Apportionment Settings article discusses the different styles available. Unfortunately, all of this will only be doable with Business Analyst desktop. That's not to say there may not be some other way to get a similar result using ArcGIS without any extensions... Yeah, I've tried all of that, including creating a custom BDS layer and then doing the append with that. None of that has worked either. Assuming the data is evenly distributed throughout each grid, is there a way I can calculate how much of each grid is within the 1 mile trade area?
... View more
06-29-2012
01:46 PM
|
0
|
0
|
194
|
POST
|
So basically, I've got employee data within quarter-mile grids for different states. So there is a grid covering the entire state, each grid 1/4 mile apart, with a employee data within each of those 1/4 squares. The data represents the entire 1/4 mile, it's not individual points. I then also have 1 mile buffers around different cities throughout those states. I need to determine how many employees are within each of those buffers. However, whenever I append the grids to the buffers, it counts the ENTIRE grid, even if a portion of it goes outside that buffer. I need it so it does not include any data outside of the buffer. I have tried to use both the clip and intersect tool. Both tools did clip the grids spatially, but they did not change the data in terms of numbers of employees whatsoever. Any ideas?
... View more
06-29-2012
12:07 PM
|
0
|
3
|
773
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|