Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ By default, the script expects CSV data be in the format specified in the sample

csvToGeoJSON arguments (all optional):

-h, --help Show this help message and exit
--verbose, --v Show parameters, detailed messages and geoJSON output
--csv CSV Filepath/name of CVS input file
-h, --help Show this help message and exit
--verbose, --v Show parameters, detailed messages and geoJSON output
--csv CSV Filepath/name of CVS input file
Default: sample.csv
--output OUTPUT Filepath/name of GeoJSON output file
--output OUTPUT Filepath/name of GeoJSON output file
Default: output.geojson
--columns COLUMNS JSON-formatted dictionary that maps CSV column names to
--columns COLUMNS JSON-formatted dictionary that maps CSV column names to
GeoJSON fields.
Default: "{ 'id':'id', 'latitude':'lat', 'longitude':'lon', 'name':'name', 'value':'pop' }"
where each name:value pair is {geoJSON-column}:{CSV-column}
Note: CSV columns don't have to appear in a particular order since the position of the data columns will be determined from their order in the CSV header (first row).
If CSV contains no ID field, specifying 'id':'-auto-' will automatically generate an ID value based on the row # of the CSV. Otherwise, the ID value will be 0.
Note: CSV columns don't have to appear in a particular order since the position of the data columns
will be determined from their order in the CSV header (first row).
If CSV contains no ID field, specifying 'id':'-auto-' will automatically generate an ID value based
on the row # of the CSV. Otherwise, the ID value will be 0.

Questions and comments to info@andrewdyck.com
Questions and comments to info@andrewdyck.com or srjones1618@gmail.com
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-architect
6 changes: 3 additions & 3 deletions csv/country_cap_latlon.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Country,Capital City,Latitude,Longitude,lat,lon
Afghanistan,Kabul,34.28N,69.11E,34.28,69.11
Albania,Tirane,41.18N,19.49E,41.18,19.49
Algeria,Algiers,36.42N,03.08E,36.42,3.08
Afghanistan,Kabul,34.28N,69.11E,34.536723,69.192827
Albania,Tirana,41.18N,19.49E,41.328074,19.821418
Algeria,Algiers,36.42N,03.08E,36.740122,3.087794
American Samoa,Pago Pago,14.16S,170.43W,-14.16,-170.4
Andorra,Andorra la Vella,42.31N,01.32E,42.31,1.32
Angola,Luanda,08.50S,13.15E,-8.5,13.15
Expand Down
11 changes: 5 additions & 6 deletions csvToGeoJSON.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main():
"id" : %s,
"geometry" : {
"type" : "Point",
"coordinates" : ["%s","%s"]
"coordinates" : [%s,%s]
},
"properties" : {
"name" : "%s",
Expand All @@ -88,8 +88,8 @@ def main():
}"""

# the head of the geojson file
output = """{ "type" : "Feature Collection",
{ "features" : ["""
output = """{ "type" : "FeatureCollection",
"features" : ["""

# loop through the csv by row skipping the first
iRow = 0
Expand Down Expand Up @@ -145,17 +145,16 @@ def main():
# append formated GeoJSON Feature
output += template % (
featureRow.id,
featureRow.latitude,
featureRow.longitude,
featureRow.latitude,
featureRow.name,
featureRow.value
)
iRow += 1

# the tail of the geojson file
output += """
]
}
]
}"""

# print any errors that were found
Expand Down
13 changes: 6 additions & 7 deletions output/alternative-columns-test.geoJSON
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ "type" : "Feature Collection",
{ "features" : [
{ "type" : "FeatureCollection",
"features" : [
{ "type" : "Feature",
"id" : 1,
"geometry" : {
"type" : "Point",
"coordinates" : ["65.216","33.677"]
"coordinates" : [65.216,33.677]
},
"properties" : {
"name" : "Afghanistan",
Expand All @@ -15,7 +15,7 @@
"id" : 2,
"geometry" : {
"type" : "Point",
"coordinates" : ["20.068","41.143"]
"coordinates" : [20.068,41.143]
},
"properties" : {
"name" : "Albania",
Expand All @@ -26,13 +26,12 @@
"id" : 3,
"geometry" : {
"type" : "Point",
"coordinates" : ["26.32","-14.614"]
"coordinates" : [26.32,-14.614]
},
"properties" : {
"name" : "Zambia",
"value" : "114B"
}
}
]
}
]
}
Loading