-1

I found various examples but nothing like what I'm looking for. I seem to be able to do it if I format it in a specific way but it doesn't let me add NAME and LOCID.

My ultimate goal is to create a point shapefile from this list:

This is what my text file looks like

closed as off-topic by Midavalo Mar 6 '17 at 19:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – Midavalo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • @OBMGIS have you same keys in all lines? – GeoStoneMarten Mar 6 '17 at 18:47
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. A question asking how to do something in arcpy should show your own attempt, and details of what happens when you try it. Please edit your question to include a snippet of your arcpy code attempt and info on what does/doesn't happen when you run it including any error messages. – Midavalo Mar 6 '17 at 19:22
  • @OBMGIS you might need to split your question in two. One for how to convert your text file into a CSV or table with a single header line (probably best asked on Stack Overflow) and then one to take that result and create your points. – Midavalo Mar 6 '17 at 19:24
  • Your first step is going to have to be to remove all the prefixes ('ID:', etc.) from the file. You can do that with search-and-replace in a text editor. – Dan C Mar 6 '17 at 19:30
  • @DanC my response do a valid csv to import this file. search and replace can crash file if a key exist in values... – GeoStoneMarten Mar 6 '17 at 19:35
2

Use pandas lib if keys are in same order and you have same keys in all lines to generate a valid csv

import pandas as pd

df = pd.read_csv("data.csv", sep=",|:", header=None,  skipinitialspace=True) # set separators , and : and remove initial space
df2 =df.ix[:,1::2]
df2.columns = list(df.ix[0,0::2])
df2.to_csv("data_new.csv", encoding="utf-8")

you can ignore last line and also complete this to generate XY Event layer with arcpy.

  • If you are converting it to a csv yourself, I don't see the need for you to downvote my answer, when it answers the question. – Vijay Ramesh Mar 6 '17 at 19:32
  • 1
    @VijayRamesh because it's necessary to create a valid csv or Dataframe before generate add it on a software as layer. In fact in key subject there is arcpy and this is python lin not R and Arcgis desktop. Sorry for your incomprehension – GeoStoneMarten Mar 6 '17 at 19:43
  • 1
    @GeoStoneMarten Does this account for the leading spaces? e.g. ID: 1, Name: Hyder has a space between the comma and the name – Midavalo Mar 6 '17 at 19:49
  • 1
    @Midavalo for that you need add skipinitialspace=True has parameter in read_csv method. I update part script – GeoStoneMarten Mar 6 '17 at 20:02
-2

Two answers:

Both involve converting your text file to a .CSV format as show below.

enter image description here

1) Load this in ArcMap and Add XY Data > Export as Shapefile

2) You can load this in R and write shapefile using maptools.

library(maptools)
library(sp)
trial <- read.csv("C:\\Users\\rameshv\\Desktop\\trial.csv", header=T)
coordinates(trial) <- ~LONG+LAT
writeSpatialShape(trial, "C:\\Users\\rameshv\\Desktop\\trial")

Both work.

  • You have not read the question correctly and don't take in consideration the exemple of datafile – GeoStoneMarten Mar 6 '17 at 19:23
  • @GeoStoneMarten I think this is probably one of the easiest solutions, given lack of python or R experience. I think it is unfair of an admin to downvote my answer, considering that you answered the question yourself. – Vijay Ramesh Mar 6 '17 at 19:28
  • I have an experience in R and your code can't run with the data in exemple – GeoStoneMarten Mar 6 '17 at 19:33
  • I am not talking about you. I am talking about the person who asked the question. Just super biased and unfair that you had to downvote the question. – Vijay Ramesh Mar 6 '17 at 19:34
  • VijayRamesh That is how this site works - if someone doesn't agree with your answer they are able to downvote it. You don't know who downvoted (so it possibly wasn't @GeoStoneMarten), and there is more than one who has downvoted your answer. If you are getting downvotes I recommend instead of complaining you refine/improve your answer in a way to attract upvotes. Please note that the OP isn't asking how to do this in R, they've asked how to do it in Arcpy. – Midavalo Mar 6 '17 at 19:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.