Greetings!
I am still new to Python, sorry! I have been searching through many posts on this subject and have attempted to TRY, but I feel really lost. So, any detailed guidance would be oh-so helpful for my learning at this point!
So, I am working with GIS data using ESRI software. I spatially select data from numerous sources and write it to a > delimited text file. I then manually bring that file into Excel, to then pass onto users to do their thing with. How do I automate this process?
**A snippet of code:
writeFile.write("CATEGORY> TYPE> NAME> ADDRESS> CITY> STATE> COUNTY> MISC_INFO> STATUS> COMMENTS> POINT_X> POINT_Y" + "\n")
curLocalPolice = gp.searchcursor(t_localPolice)
rowLocalPolice = curLocalPolice.Next()
while rowLocalPolice:
writeFile.write("SECURITY> LOCAL POLICE> " + rowLocalPolice.Name + "> " + rowLocalPolice.address +
"> " + rowLocalPolice.city + "> " + rowLocalPolice.state + "> " + rowLocalPolice.county +
"> " + "ph(" + str(rowLocalPolice.area_) + ")" + str(rowLocalPolice.phone) +
"> > > " + str(rowLocalPolice.point_x) + "> " + str(rowLocalPolice.point_y) + "\n")
rowLocalPolice = curLocalPolice.Next()
**which produces a text file that looks like this (way more records then this, of course):
SWEAT_CATEGORY> TYPE> NAME> ADDRESS> CITY> STATE> COUNTY> MISC_INFO> STATUS> COMMENTS> POINT_X> POINT_Y
SECURITY> LOCAL POLICE> EAST WHITELAND TOWNSHIP POLICE DEPT HEADQUARTERS> 209 CONESTOGA RD> MALVERN> PA> CHESTER> ph(610)647-2100> > > -75.5554538863> 40.050059662
SECURITY> LOCAL POLICE> EAST VINCENT TOWNSHIP POLICE DEPT HEADQUARTERS> 262 RIDGE RD> SPRING CITY> PA> CHESTER> ph(610)933-0115> > > -75.5880005882> 40.1617776533
SECURITY> LOCAL POLICE> DOWNINGTOWN POLICE DEPT HEADQUARTERS> 10 W LANCASTER AVE> DOWNINGTOWN> PA> CHESTER> ph(610)269-0263> > > -75.7061431299> 40.0048218854
SECURITY> LOCAL POLICE> UWCHLAN TOWNSHIP POLICE DEPT HEADQUARTERS> 717 N SHIP RD> EXTON> PA> CHESTER> ph(610)363-6947> > > -75.6305628031> 40.0487863475
SECURITY> LOCAL POLICE> PHOENIXVILLE POLICE DEPT HEADQUARTERS> 140 CHURCH ST> PHOENIXVILLE> PA> CHESTER> ph(610)933-1180> > > -75.5135260786> 40.1328893105
SECURITY> LOCAL POLICE> MALVERN POLICE DEPT HEADQUARTERS> 1 E 1ST AVE> MALVERN> PA> CHESTER> ph(610)647-0261> > > -75.5125783923> 40.033827335
**which I then maually bring into Excel as a > delimited file, do some column adjustments and save as a CSV file so that it can then be brought into ArcMap (GIS mapping and analysis software).
How do I automate in Python 2.4? I have this/below bit of general code. Is this right? Do I need to build a dictionary with my text file? How? Is this code inserted at the end of my script, once all data has been put to the text file?
import sys, string, os, win32com.client
gp = win32com.client.Dispatch("esriGeoprocessing.GpDisp atch.1")
#import arcgisscripting, sys
#gp = arcgisscripting.create()
worksheet = gp.GetParameterAsText(0)
inValue = gp.GetParameterAsText(1)
#worksheet = "d:\\test\\excel\\test.xls"
#inValue = 10
xlApp = win32com.client.Dispatch("Excel.Application")
#xlApp.Visible = 1
xlApp.Workbooks.Open(worksheet)
xlApp.ActiveSheet.Cells(1,1).Value = inValue
xlApp.ActiveSheet.Calculate()
outValue = xlApp.ActiveSheet.Cells(2,1).Value
xlApp.ActiveWorkbook.Close(SaveChanges=0)
xlApp.Quit()
del xlApp
gp.SetParameterAsText(2,outValue)
del gp
***Sorry to be such a long post!
I would love some serious guidance from you Python gurus, otherwise I will continue to spin, ugh.
Thanks!
2 3898
Greetings!
I am still new to Python, sorry! I have been searching through many posts on this subject and have attempted to TRY, but I feel really lost. So, any detailed guidance would be oh-so helpful for my learning at this point!
So, I am working with GIS data using ESRI software. I spatially select data from numerous sources and write it to a > delimited text file. I then manually bring that file into Excel, to then pass onto users to do their thing with. How do I automate this process?
**A snippet of code:
writeFile.write("CATEGORY> TYPE> NAME> ADDRESS> CITY> STATE> COUNTY> MISC_INFO> STATUS> COMMENTS> POINT_X> POINT_Y" + "\n")
curLocalPolice = gp.searchcursor(t_localPolice)
rowLocalPolice = curLocalPolice.Next()
while rowLocalPolice:
writeFile.write("SECURITY> LOCAL POLICE> " + rowLocalPolice.Name + "> " + rowLocalPolice.address +
"> " + rowLocalPolice.city + "> " + rowLocalPolice.state + "> " + rowLocalPolice.county +
"> " + "ph(" + str(rowLocalPolice.area_) + ")" + str(rowLocalPolice.phone) +
"> > > " + str(rowLocalPolice.point_x) + "> " + str(rowLocalPolice.point_y) + "\n")
rowLocalPolice = curLocalPolice.Next()
**which produces a text file that looks like this (way more records then this, of course):
SWEAT_CATEGORY> TYPE> NAME> ADDRESS> CITY> STATE> COUNTY> MISC_INFO> STATUS> COMMENTS> POINT_X> POINT_Y
SECURITY> LOCAL POLICE> EAST WHITELAND TOWNSHIP POLICE DEPT HEADQUARTERS> 209 CONESTOGA RD> MALVERN> PA> CHESTER> ph(610)647-2100> > > -75.5554538863> 40.050059662
SECURITY> LOCAL POLICE> EAST VINCENT TOWNSHIP POLICE DEPT HEADQUARTERS> 262 RIDGE RD> SPRING CITY> PA> CHESTER> ph(610)933-0115> > > -75.5880005882> 40.1617776533
SECURITY> LOCAL POLICE> DOWNINGTOWN POLICE DEPT HEADQUARTERS> 10 W LANCASTER AVE> DOWNINGTOWN> PA> CHESTER> ph(610)269-0263> > > -75.7061431299> 40.0048218854
SECURITY> LOCAL POLICE> UWCHLAN TOWNSHIP POLICE DEPT HEADQUARTERS> 717 N SHIP RD> EXTON> PA> CHESTER> ph(610)363-6947> > > -75.6305628031> 40.0487863475
SECURITY> LOCAL POLICE> PHOENIXVILLE POLICE DEPT HEADQUARTERS> 140 CHURCH ST> PHOENIXVILLE> PA> CHESTER> ph(610)933-1180> > > -75.5135260786> 40.1328893105
SECURITY> LOCAL POLICE> MALVERN POLICE DEPT HEADQUARTERS> 1 E 1ST AVE> MALVERN> PA> CHESTER> ph(610)647-0261> > > -75.5125783923> 40.033827335
**which I then maually bring into Excel as a > delimited file, do some column adjustments and save as a CSV file so that it can then be brought into ArcMap (GIS mapping and analysis software).
How do I automate in Python 2.4? I have this/below bit of general code. Is this right? Do I need to build a dictionary with my text file? How? Is this code inserted at the end of my script, once all data has been put to the text file?
import sys, string, os, win32com.client
gp = win32com.client.Dispatch("esriGeoprocessing.GpDisp atch.1")
#import arcgisscripting, sys
#gp = arcgisscripting.create()
worksheet = gp.GetParameterAsText(0)
inValue = gp.GetParameterAsText(1)
#worksheet = "d:\\test\\excel\\test.xls"
#inValue = 10
xlApp = win32com.client.Dispatch("Excel.Application")
#xlApp.Visible = 1
xlApp.Workbooks.Open(worksheet)
xlApp.ActiveSheet.Cells(1,1).Value = inValue
xlApp.ActiveSheet.Calculate()
outValue = xlApp.ActiveSheet.Cells(2,1).Value
xlApp.ActiveWorkbook.Close(SaveChanges=0)
xlApp.Quit()
del xlApp
gp.SetParameterAsText(2,outValue)
del gp
***Sorry to be such a long post!
I would love some serious guidance from you Python gurus, otherwise I will continue to spin, ugh.
Thanks!
Sorry, forgot code brackets.
**A snippet of code: -
writeFile.write("CATEGORY> TYPE> NAME> ADDRESS> CITY> STATE> COUNTY> MISC_INFO> STATUS> COMMENTS> POINT_X> POINT_Y" + "\n")
-
-
curLocalPolice = gp.searchcursor(t_localPolice)
-
rowLocalPolice = curLocalPolice.Next()
-
while rowLocalPolice:
-
writeFile.write("SECURITY> LOCAL POLICE> " + rowLocalPolice.Name + "> " + rowLocalPolice.address +
-
"> " + rowLocalPolice.city + "> " + rowLocalPolice.state + "> " + rowLocalPolice.county +
-
"> " + "ph(" + str(rowLocalPolice.area_) + ")" + str(rowLocalPolice.phone) +
-
"> > > " + str(rowLocalPolice.point_x) + "> " + str(rowLocalPolice.point_y) + "\n")
-
rowLocalPolice = curLocalPolice.Next()
-
-
import sys, string, os, win32com.client
-
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
-
-
#import arcgisscripting, sys
-
#gp = arcgisscripting.create()
-
-
worksheet = gp.GetParameterAsText(0)
-
inValue = gp.GetParameterAsText(1)
-
-
#worksheet = "d:\\test\\excel\\test.xls"
-
#inValue = 10
-
-
xlApp = win32com.client.Dispatch("Excel.Application")
-
#xlApp.Visible = 1
-
xlApp.Workbooks.Open(worksheet)
-
xlApp.ActiveSheet.Cells(1,1).Value = inValue
-
xlApp.ActiveSheet.Calculate()
-
outValue = xlApp.ActiveSheet.Cells(2,1).Value
-
xlApp.ActiveWorkbook.Close(SaveChanges=0)
-
xlApp.Quit()
-
del xlApp
-
-
gp.SetParameterAsText(2,outValue)
-
del gp
-
This thread can be closed. I figured it out on my own.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrew V. Romero |
last post by:
At work we have an excel file that contains the list of medications and
their corresponding strengths. I would like to save the excel file as a
text list and paste this list into a javascript...
|
by: Wade G. Pemberton |
last post by:
Help!:
I use javascript to format repetitive data from a web page input FORM
into a long string , and save it as lines of comma delimited data in a
text file on a Unix server. The text...
|
by: Johnny Meredith |
last post by:
I have seven huge fixed width text file that I need to import to Access.
They contain headers, subtotals, etc. that are not needed. There is also
some corrupt data that we know about and can...
|
by: mail2atulmehta |
last post by:
Hi,
I do not know if this is right place for this, but i need some help. I
have a text file, whose values are seprated by a delimiter. I want to
open this file in excel, ( not import it) . I have...
|
by: dgoel |
last post by:
Hi,
I Have a text file & I want to open it in excel sheet ( withou
importing). I have written code for it, but it is not opening exce
sheet. It opens the text file, but does not create a excel...
|
by: shantanu |
last post by:
Hi all
i am trying to save a excel file as a tab delimited text file. can i
do it some how?
i using the code
_sheet1.SaveAs(@"C:\PRP
\PRPTemp.txt",Excel.XlFileFormat.xlTextWindows...
|
by: sukhmeet |
last post by:
Hi,
I am trying to load a csv file in Iframe element. I just want to
load it as a text file.
however when i load the file in iframe it asks to open the file and
finally opens it with excel in IE...
|
by: pulavarthipraveen |
last post by:
Overview: We have a requirement in the c#.NET 1.0 windows application. There will be some input text file in the user’s machine. The user should browse and select the input text file and also select...
|
by: pakerly |
last post by:
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |