Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON make the necessary changes to map.py to produce a file_houston.geojson file. Go out to http://geojsonlint.com/ to test your file. Remember to open your .geojson

PYTHON

make the necessary changes to map.py to produce a file_houston.geojson file.

Go out to http://geojsonlint.com/ to test your file. Remember to open your .geojson file in notepad, select FeatureCollection on the web site, then copy and paste the code into the box provided to see your data plotted on a map.

MAP.PY

""" Data Visualization Project Parse data from an ugly CSV or Excel file, and render it in JSON-like form, visualize in graphs, and plot as a map. Part III: Take the data we parsed earlier and create a different format for rendering a map. Here, we parse through each line item of the CSV file and create a geojson object, to be collected into one geojson file for uploading to gist.github.com. """

import geojson

import parse as p

def create_map(data_file): """Creates a GeoJSON file. Returns a GeoJSON file that can be rendered in a GitHub Gist at gist.github.com. Just copy the output file and paste into a new Gist, then create either a public or private gist. GitHub will automatically render the GeoJSON file as a map. """

# Define type of GeoJSON we're creating geo_map = {"type": "FeatureCollection"}

# Define empty list to collect each point to graph item_list = []

# Iterate over our data to create GeoJSOn document. # We're using enumerate() so we get the line, as well # the index, which is the line number. for index, line in enumerate(data_file):

# Skip any zero coordinates as this will throw off # our map. if line['X'] == "0" or line['Y'] == "0": continue

# Setup a new dictionary for each iteration. data = {}

# Assign line items to appropriate GeoJSON fields. data['type'] = 'Feature' data['properties'] = {'title': line['Category'], 'description': line['Descript'], 'date': line['Date']} data['geometry'] = {'type': 'Point', 'coordinates': (float(line['X']), float(line['Y']))}

# Add data dictionary to our item_list item_list.append(data)

# For each point in our item_list, we add the point to our # dictionary. setdefault creates a key called 'features' that # has a value type of an empty list. With each iteration, we # are appending our point to that list. for point in item_list: geo_map.setdefault('features', []).append(point)

# Now that all data is parsed in GeoJSON write to a file so we # can upload it to gist.github.com with open('file_sf.geojson', 'w') as f: f.write(geojson.dumps(geo_map))

def main(): data = p.parse(p.MY_FILE, ",")

return create_map(data)

if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions

Question

To find integral of sin(logx) .

Answered: 1 week ago