Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hohyon-ryu committed Aug 19, 2011
0 parents commit 3bff961
Show file tree
Hide file tree
Showing 10 changed files with 30,255 additions and 0 deletions.
67 changes: 67 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
py_geo_voronoi

Created by Hohyon Ryu, Aug/19/2011

* Dependencies

- shapely : sudo apt-get install python-shapely
- matplotlib (pylab) : sudo apt-get install python-matplotlib
- Built on Steve Fortune's Python Voronoi Code
Steve Fortune's homepage: http://netlib.bell-labs.com/cm/cs/who/sjf/index.html

* Inputs:
1. Dictionary of the points: (You can use simple sequential number for the dictionary keys or some text to associate with.)
PointsMap={}
PointsMap["stationA"]=(-143.22, 38.22)
PointsMap["stationB"]=(-122.22, 56.22)
PointsMap[1]=(-122.22, 56.22)

2. The bounding box (left_top_x, left_top_y, bottom_right_x, bottom_right,y) to generate a voronoi lattice.
Bounding Box Options: You can either use the name or the coordinates
"AUSTIN" [30.8, -98.5, 29.535, -97.031]
"TX" [36.5, -106, 25, -93]
"US" [55, -130, 23, -60]
"GUS" [60, -140, 22, -50]
"KR" [45, 120, 32, 135] (Korea)
"W" [90, -180, -90, 180] (World, Default)

3. PlotMap: shows the voronoi lattice on a map. This may be extremely slow if you have more than 1M points. (Default is False, Not available for VoronoiLineEdges)


* Output options:
1. Stations, Lines and edges
2. Polygons
3. GeoJson Polygons
4. GeoJson MultiPolygons

Example:
import voronoi_poly

vl=voronoi_poly.VoronoiLineEdges(PointsMap)
Output:
vertices, lines, edges, station_to_edge
(1) a list of 2-tuples, which are the x,y coordinates of the
Voronoi diagram vertices
(2) a list of 3-tuples (a,b,c) which are the equations of the
lines in the Voronoi diagram: a*x + b*y = c
(3) a list of 3-tuples, (l, v1, v2) representing edges of the
Voronoi diagram. l is the index of the line, v1 and v2 are
the indices of the vetices at the end of the edge. If
v1 or v2 is -1, the line extends to infinity.
(4) a dictionary, where keys are the station numbers(vertices), and the
values are the number of edges surrounding the vertice.

vl=voronoi_poly.VoronoiPolygons(PointsMap, BoundingBox="AUSTIN", PlotMap=False)
Output:
185: {'coordinate': (3.04, 36.77), 'info': 'Algiers/Algeria', 'obj_polygon': <shapely.geometry.polygon.Polygon object at 0x3152190>}

- You can access the polygon coordinates by the following example:

from shapely.geometry import Polygon
print list(polygon_data.exterior.coords)

vl=voronoi_poly.VoronoiGeoJson_Polygons(PointsMap, BoundingBox="US")

vl=voronoi_poly.VoronoiGeoJson_MultiPolygons(PointsMap, BoundingBox="KR")


30 changes: 30 additions & 0 deletions main_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! /usr/local/bin/python

import sys
import voronoi_poly

#Run this using the pipe: "cat sample_city_data | python main_example.py"
if __name__=="__main__":

#Creating the PointsMap from the input data
PointsMap={}
for line in sys.stdin:
data=line.strip().split(",")
try:
PointsMap[data[0]]=(float(data[1]),float(data[2]))
except:
sys.stderr.write( "Invalid Input Line: "+line)

#vl=voronoi_poly.VoronoiLineEdges(PointsMap)
#vertices, lines, edges, station_to_edge
#print vl

#vl=voronoi_poly.VoronoiPolygons(PointsMap, BoundingBox="W", PlotMap=True)
#print vl

#cat sample_city_data | python main_example.py > out.geojson
#vl=voronoi_poly.VoronoiGeoJson_Polygons(PointsMap, BoundingBox="W", PlotMap=False)

vl=voronoi_poly.VoronoiGeoJson_MultiPolygons(PointsMap, BoundingBox="W", PlotMap=False)
print vl

1 change: 1 addition & 0 deletions out.geojson

Large diffs are not rendered by default.

201 changes: 201 additions & 0 deletions sample_city_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
x,y
Aba/Nigeria,7.35,5.1
Abidjan/Ivory Coast,-4.03,5.33
Accra/Ghana,-0.2,5.56
Addis abeba/Ethiopia,38.74,9.03
Agra/India,78.01,27.19
Ahmadabad/India,72.58,23.03
Al-Basrah/Iraq,47.82,30.53
Aleppo/Syria,37.17,36.23
Alexandria/Egypt,29.95,31.22
Algiers/Algeria,3.04,36.77
Al-MawSil/Iraq,43.14,36.34
Ankara/Turkey,32.85,39.93
Antananarivo/Madagascar,47.51,-18.89
Bagdad/Iraq,44.44,33.33
Bamako/Mali,-7.99,12.65
Bandung/Indonesia,107.6,-6.91
Bangalore/India,77.56,12.97
Bangkok/Thailand,100.5,13.73
Barcelona/Spain,2.17,41.4
Bayrut/Lebanon,35.5,33.89
Bekasi/Indonesia,106.97,-6.22
Belem/Brazil,-48.5,-1.44
Belo Horizonte/Brazil,-43.94,-19.92
Benin/Nigeria,5.62,6.34
Berlin/Germany,13.38,52.52
Bhopal/India,77.4,23.24
Bogota/Colombia,-74.09,4.63
Bombay/India,72.82,18.96
Brasilia/Brazil,-47.91,-15.78
Brisbane/Australia,153.02,-27.46
Bucharest/Romania,26.1,44.44
Budapest/Hungary,19.08,47.51
Buenos Aires/Argentina,-58.37,-34.61
Bursa/Turkey,29.08,40.2
Cairo/Egypt,31.25,30.06
Calcutta/India,88.36,22.57
Cali/Colombia,-76.52,3.44
Cape Town/South Africa,18.46,-33.93
Caracas/Venezuela,-66.93,10.54
Casablanca/Morocco,-7.62,33.6
Changchun/China,125.35,43.87
Changsha/China,112.97,28.2
Chattagam/Bangladesh,91.81,22.33
Chengdu/China,104.07,30.67
Chicago/United States of America,-87.68,41.84
Chongqing/China,106.58,29.57
Conakry/Guinea,-13.67,9.55
Cordoba/Argentina,-64.19,-31.4
Curitiba/Brazil,-49.29,-25.42
Dakar/Senegal,-17.48,14.72
Dalian/China,121.65,38.92
Damascus/Syria,36.32,33.5
Dar es Salaam/Tanzania,39.28,-6.82
Davao/Philippines,125.63,7.11
Delhi/India,77.21,28.67
Dhaka/Bangladesh,90.39,23.7
Douala/Cameroon,9.71,4.06
Dubai/United Arab Emirates,55.33,25.27
Durban/South Africa,30.99,-29.87
Ecatepec/Mexico,-99.05,19.6
Esfahan/Iran,51.68,32.68
Faisalabad/Pakistan,73.11,31.41
Fortaleza/Brazil,-38.59,-3.78
Gaoxiong/Taiwan,120.27,22.63
Gizeh/Egypt,31.21,30.01
Guadalajara/Mexico,-103.35,20.67
Guangzhou/China,113.25,23.12
Guayaquil/Ecuador,-79.9,-2.21
Gujranwala/Pakistan,74.18,32.16
Hamburg/Germany,10.0,53.55
Hangzhou/China,120.17,30.25
Harare/Zimbabwe,31.05,-17.82
Harbin/China,126.65,45.75
Havanna/Cuba,-82.39,23.13
Ho Chi Minh City/Vietnam,106.69,10.78
Houston/United States of America,-95.39,29.77
Hyderabad/India,78.48,17.4
Hyderabad/Pakistan,68.37,25.38
Ibadan/Nigeria,3.93,7.38
Incheon/Korea (South),126.64,37.48
Indore/India,75.86,22.72
Istanbul/Turkey,29.0,41.1
Izmir/Turkey,27.15,38.43
Jaipur/India,75.8,26.92
Jakarta/Indonesia,106.83,-6.18
Jiddah/Saudi Arabia,39.17,21.5
Jilin/China,126.55,43.85
Jinan/China,117.0,36.67
Jiulong/China,114.17,22.32
Johannesburg/South Africa,28.04,-26.19
Juarez/Mexico,-106.49,31.74
Kabul/Afghanistan,69.17,34.53
Kaduna/Nigeria,7.44,10.52
Kano/Nigeria,8.52,12.0
Kanpur/India,80.33,26.47
Karachi/Pakistan,67.01,24.86
Karaj/Iran,50.97,35.8
Khartoum/Sudan,32.52,15.58
Kiev/Ukraine,30.52,50.43
Kinshasa/Congo (Dem. Rep.),15.32,-4.31
Kobe/Japan,135.17,34.68
Koyang/Korea (South),126.93,37.7
Kumasi/Ghana,-1.63,6.69
Lagos/Nigeria,3.35,6.5
Lahore/Pakistan,74.35,31.56
Lakhnau/India,80.92,26.85
Lima/Peru,-77.05,-12.07
Lome/Togo,1.35,6.17
London/United Kingdom,-0.1,51.52
Los Angeles/United States of America,-118.41,34.11
Luanda/Angola,13.24,-8.82
Lubumbashi/Congo (Dem. Rep.),27.48,-11.66
Ludhiana/India,75.84,30.91
Madras/India,80.27,13.09
Madrid/Spain,-3.71,40.42
Manaus/Brazil,-60.02,-3.12
Manila/Philippines,120.97,14.62
Maracaibo/Venezuela,-71.66,10.73
Mashhad/Iran,59.57,36.27
Mbuji-Mayi/Congo (Dem. Rep.),23.59,-6.13
Medan/Indonesia,98.67,3.59
Medellin/Colombia,-75.54,6.29
Melbourne/Australia,144.96,-37.81
Mexico City/Mexico,-99.14,19.43
Minsk/Belarus,27.55,53.91
Montreal/Canada,-73.57,45.52
Moscow/Russia,37.62,55.75
Multan/Pakistan,71.45,30.2
Muqdisho/Somalia,45.33,2.05
Nagoya/Japan,136.91,35.15
Nagpur/India,79.08,21.16
Nairobi/Kenya,36.82,-1.29
Nanchang/China,115.88,28.68
Nanjing/China,118.78,32.05
Nashik/India,73.78,20.01
New York/United States of America,-73.94,40.67
osaka/Japan,135.5,34.68
Paris/France,2.34,48.86
Patna/India,85.13,25.62
Peking/China,116.4,39.93
Phoenix/United States of America,-112.07,33.54
Pimpri/India,73.8,18.62
Port Harcourt/Nigeria,7.01,4.81
Pretoria/South Africa,28.22,-25.73
Pune/India,73.84,18.53
Pusan/Korea (South),129.03,35.11
Pyeongyang/Korea (North),125.75,39.02
Qingdao/China,120.32,36.07
Quito/Ecuador,-78.5,-0.19
Rabat/Morocco,-6.84,34.02
Rangoon/Myanmar,96.15,16.79
Rawalpindi/Pakistan,73.04,33.6
Recife/Brazil,-34.92,-8.08
Rio de Janeiro/Brazil,-43.2,-22.91
Riyadh/Saudi Arabia,46.77,24.65
Rome/Italy,12.5,41.89
Rongcheng/China,116.34,23.54
Saint Petersburg/Russia,30.32,59.93
Salvador/Brazil,-38.5,-12.97
Sana/Yemen,44.21,15.38
Santa Cruz/Bolivia,-63.21,-17.77
Santiago/Chile,-70.64,-33.46
Santo Domingo/Dominican Republic,-69.91,18.48
São Paulo/Brazil,-46.63,-23.53
Sapporo/Japan,141.34,43.06
Shanghai/China,121.47,31.23
Shenyang/China,123.45,41.8
Shijiazhuang/China,114.48,38.05
Singapore/Singapore,103.85,1.3
Seoul/Korea (South),126.99,37.56
Soweto/South Africa,27.84,-26.28
Subang Jaya/Malaysia,101.53,3.15
Surabaya/Indonesia,112.74,-7.24
Surat/India,72.82,21.2
Suzhou/China,120.62,31.3
Sydney/Australia,151.21,-33.87
Taegu/Korea (South),128.6,35.87
Taibei/Taiwan,121.45,25.02
Taiyuan/China,112.55,37.87
Tangshan/China,118.19,39.62
Tashkent/Uzbekistan,69.3,41.31
Tehran/Iran,51.43,35.67
Thana/India,72.97,19.2
Tianjin/China,117.2,39.13
Tijuana/Mexico,-117.02,32.53
Tokyo/Japan,139.77,35.67
Toronto/Canada,-79.38,43.65
Umm Durman/Sudan,32.48,15.65
Urumqi/China,87.58,43.8
Vadodara/India,73.18,22.31
Valencia/Venezuela,-67.98,10.23
Vancouver/Canada,-123.13,49.28
Vienna/Austria,16.37,48.22
Warsaw/Poland,21.02,52.26
Wuhan/China,114.27,30.58
Xian/China,108.9,34.27
Xinyang/China,114.07,32.13
Yaounde/Cameroon,11.52,3.87
Yokohama/Japan,139.62,35.47
Zhengzhou/China,113.67,34.75
Loading

0 comments on commit 3bff961

Please sign in to comment.