|
POST
|
Hi Durga, What version of ArcGIS Desktop are you running (including service packs)? Do you have a sample dataset you could upload that exhibits this behavior?
... View more
12-05-2012
03:04 AM
|
0
|
0
|
1051
|
|
POST
|
Would you be able to upload a sample set of your data?
... View more
12-05-2012
02:44 AM
|
0
|
0
|
1748
|
|
POST
|
Hi Thomas, You could start with something like this: fc = "lines"
rows = arcpy.SearchCursor(fc)
for row in rows:
geom = row.Shape
rows2 = arcpy.UpdateCursor(fc)
for row2 in rows2:
if row2.shape.touches(geom):
print str(row.OBJECTID) + " touches " + str(row2.OBJECTID)
row2.ID = row.OBJECTID
rows2.updateRow(row2)
del row, rows, row2, rows2 I have not thoroughly tested the code, but this could get you started.
... View more
12-04-2012
03:38 AM
|
0
|
0
|
1748
|
|
POST
|
Hi Joe, You could use the following expression: [DATE_FIELD] > #10-06-2011 00:00:00# AND [DATE_FIELD] < #10-06-2011 23:59:59# This will select all the records with a date of 10/6/2011.
... View more
12-03-2012
10:55 AM
|
0
|
0
|
860
|
|
POST
|
Hi Mike, This is a bug and has been logged: NIM084842: Support GlobalID field type with arcpy.da.SearchCursor. You can follow the status of this bug on support.esri.com.
... View more
12-03-2012
02:31 AM
|
0
|
0
|
3186
|
|
POST
|
The below should work. I added the additional code to a new function called 'reformat' and then called this function when CSV is chosen for the format type. # -*- coding: utf-8 -*-
"""
This script will convert a table to an excel spreadsheet. If the third-party
module xlwt is available, it will use that. Otherwise, it will fall back to
CSV.
"""
import arcgisscripting
import os
gp = arcgisscripting.create(9.3)
def header_and_iterator(dataset_name):
"""Returns a list of column names and an iterator over the same columns"""
data_description = gp.Describe(dataset_name)
fieldnames = [f.name for f in data_description.fields if f.type not in ["Geometry", "Raster", "Blob"]]
def iterator_for_feature():
cursor = gp.SearchCursor(dataset_name)
row = cursor.next()
while row:
yield [getattr(row, col) for col in fieldnames]
row = cursor.next()
del row, cursor
return fieldnames, iterator_for_feature()
def export_to_csv(dataset, output):
"""Output the data to a CSV file"""
import csv
def _encode(x):
if isinstance(x, unicode):
return x.encode("utf-8")
else:
return str(x)
def _encodeHeader(x):
return _encode(x.replace(".","_"))
out_writer = csv.writer(open(output, 'wb'))
header, rows = header_and_iterator(dataset)
out_writer.writerow(map(_encodeHeader, header))
for row in rows:
out_writer.writerow(map(_encode, row))
def export_to_xls(dataset, output):
"""
Attempt to output to an XLS file. If xmlwt is not available, fall back
to CSV.
XLWT can be downloaded from http://pypi.python.org/pypi/xlwt"""
try:
import xlwt
except ImportError:
gp.AddError("import of xlwt module failed")
return
header, rows = header_and_iterator(dataset)
# Make spreadsheet
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet(os.path.split(dataset)[1])
#Set up header row, freeze panes
header_style = xlwt.easyxf("font: bold on; align: horiz center")
for index, colheader in enumerate(header):
worksheet.write(0, index, colheader.replace(".","_"))
worksheet.set_panes_frozen(True)
worksheet.set_horz_split_pos(1)
worksheet.set_remove_splits(True)
# Write rows
for rowidx, row in enumerate(rows):
for colindex, col in enumerate(row):
worksheet.write(rowidx+1, colindex, col)
# All done
workbook.save(output)
def reformat(output):
import csv
#read lines of CSV
f = open(output, "r")
lines=f.readlines()
lines=lines[1:]
f.close()
#write all lines except header to CSV
f = open(output, "w+")
for line in lines:
f.write(line)
f.close()
#remove first column
with open(output,"r") as input:
with open(output + "_1", "w+") as output2:
writer=csv.writer(output2)
for row in csv.reader(input):
writer.writerow(row[1:])
#remove empty rows
input = open(output + "_1", 'rb')
output2 = open(output + "_2", 'wb')
writer = csv.writer(output2)
for row in csv.reader(input):
if row:
writer.writerow(row)
input.close()
output2.close()
os.remove(output)
os.remove(output + "_1")
#rename to original CSV
os.rename(output + "_2", output)
if __name__ == "__main__":
dataset_name = gp.GetParameterAsText(0)
output_file = gp.GetParameterAsText(1)
format = gp.GetParameterAsText(2)
if format == "CSV":
export_to_csv(dataset_name, output_file)
reformat(output_file)
elif format == "XLS":
try:
export_to_xls(dataset_name, output_file)
except:
import traceback
gp.AddError(traceback.format_exc())
else:
raise ValueError("Don't know how to export to %r" % format)
print "FINISHED"
... View more
11-30-2012
03:11 AM
|
0
|
0
|
1910
|
|
POST
|
Hi Randall, I didn't see a script attached to your post, but you can try adding the below code to your script:
import csv, os
table = r"C:\temp\python\XY.csv"
outFile = r"C:\temp\python\XY_1.csv"
outFile2 = r"C:\temp\python\XY_2.csv"
#read lines of CSV
f = open(table, "r")
lines=f.readlines()
lines=lines[1:]
f.close()
#write all lines except header to CSV
f = open(table, "w+")
for line in lines:
f.write(line)
f.close()
#remove first column
with open(table,"r") as input:
with open(outFile,"w+") as output:
writer=csv.writer(output)
for row in csv.reader(input):
writer.writerow(row[1:])
#remove empty rows
input = open(outFile, 'rb')
output = open(outFile2, 'wb')
writer = csv.writer(output)
for row in csv.reader(input):
if row:
writer.writerow(row)
input.close()
output.close()
os.remove(table)
os.remove(outFile)
#rename to original CSV
os.rename(outFile2, table)
print "Finished" The 'table' variable is your original CSV file. 'outFile' and 'outFile2' do not need to exist; these will be created on the fly. Also, this code assumes the FID field is the first column in your CSV file. For some reason, after removing the first column the output CSV file contained an empty row between each row. That is why there is code to remove empty rows.
... View more
11-29-2012
02:15 AM
|
0
|
0
|
1910
|
|
POST
|
What is the error you receive when you execute this code?
... View more
11-28-2012
03:21 AM
|
0
|
0
|
1568
|
|
POST
|
Can you post the code that you're using? Also, what is the error you are receiving?
... View more
11-26-2012
08:45 AM
|
0
|
0
|
1568
|
|
POST
|
What type of layer is this? (i.e. SDE feature class, File Geodatabase feature class, shapefile)? Are there any schema locks? For example if an ArcGIS Server service is using this data, that would place a schema lock on the data. Can you post a screen shot of the error you are receiving?
... View more
11-26-2012
06:59 AM
|
0
|
0
|
1230
|
|
POST
|
Hi Sven, In your script specify the Temp drive using a UNC path. Ex: \\<ArcGIS Server name\Temp Note: be sure the Temp drive is shared Another option is to publish your script to ArcGIS Server. The output shapefile will then be written to you 'arcgisjobs' folder on your ArcGIS Server machine.
... View more
11-26-2012
06:39 AM
|
0
|
0
|
1568
|
|
POST
|
It looks like you have SQL Server 2012 Express installed correctly. Do you have ArcGIS 10.1 for Desktop installed on your machine? If you do, you can use the new Create Enterprise Geodatabase geoprocessing tool in ArcToolbox to create your geodatabase.
... View more
11-26-2012
06:16 AM
|
0
|
0
|
2275
|
|
POST
|
Hi Michael, If you have the Spatial Analyst extension you can easily perform an image classification using the image classification toolbar. With this toolbar you can create training samples and then perform a interactive supervised classification.
... View more
11-26-2012
01:57 AM
|
0
|
0
|
672
|
|
POST
|
Hi Scott, If SQL Server is installed on your server, you will want to specify your server name plus "\sqlexpress". Ex: SCOTTCHANG_PC\sqlexpress However, I don't believe SQL Server 2012 is supported with ArcGIS 10.0 (it is 10.1). It may work, but you may encounter some problems.
... View more
11-21-2012
09:09 AM
|
0
|
0
|
2275
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 4 weeks ago | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|