0

The coordinates of the vertices representing the street Kochstraße in Erlangen are stored in a text file called Koord_Strasse.csv. Write a script to create a new feature class and add the point objects of the Kochstraße geometry to that feature class. Set the spatial reference of the new feature class to UTM Zone 32N, WGS 84. For this, you can obtain the spatial reference information from an existing feature class in Ueb5.gdb.

File CSV:

1,645801.70688,5496227.23548
2,645803.02980,5496225.51569
3,645803.55897,5496223.39901
4,645803.02980,5496220.22401
5,645792.44645,5496191.91353
6,645783.58289,5496167.70411
7,645776.43912,5496147.99261
8,645771.67661,5496136.88009
9,645763.20993,5496111.87692
10,645753.02345,5496085.41853
11,645746.93802,5496067.95600
12,645738.33905,5496045.33408
13,645734.76716,5496036.86739
14,645732.12219,5496029.93573

Unfortunately, I can't run the code with the file CSV with comma signs "," as above. I only run it when I change .csv file to .txt file and delete comma signs in txt file, for example:

1 645801.70688 5496227.23548
2 645803.02980 5496225.51569
3 645803.55897 5496223.39901
4 645803.02980 5496220.22401
5 645792.44645 5496191.91353
6 645783.58289 5496167.70411
7 645776.43912 5496147.99261
8 645771.67661 5496136.88009
9 645763.20993 5496111.87692
10 645753.02345 5496085.41853
11 645746.93802 5496067.95600
12 645738.33905 5496045.33408
13 645734.76716 5496036.86739
14 645732.12219 5496029.93573 

Who can show me how to put delimiter "," out the CSV file ???

My code:

import arcpy, fileinput, os, string
arcpy.env.workspace = "D:\Data_Session5\Data_Session5"
arcpy.env.overwriteOutput = True
outpath = "D:\Data_Session5\Data_Session5"
newfc = "Street_Koord_Strasse.shp"
arcpy.CreateFeatureclass_management(outpath, newfc, "Polyline","", "", "", "D:\Data_Session5\Data_Session5\Ueb5.gdb\seen_ER")
infile = "D:\Data_Session5\Data_Session5\Koord_Strasse.csv" 
cursor = arcpy.da.InsertCursor(newfc, ["SHAPE@"])
array = arcpy.Array()
for line in fileinput.input(infile):
    ID, X, Y = string.split(line, " ")
    array.add(arcpy.Point(X, Y))
cursor.insertRow([arcpy.Polyline(array)])
fileinput.close()
del cursor
  • 1
    Since this is homework, I will not answer it for you but try to lead you to the solution. Later I would turn the exchange into an answer. First question: Where in your code is the data from the csv file read and processed? – bugmenot123 Dec 19 '18 at 10:42
  • 1
    Did you write this code yourself? Understanding the operation of the str.split function is outside the scope of GIS SE. Your code snippet could be just five lines, ignoring all arcpy and still have the same issue. The assignment explicitly states that you need to retrieve and use the SRID, but your code doesn't. – Vince Dec 19 '18 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.