mapplz 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -25
- data/lib/mapplz.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92d4497b2e8222e35370a7aeaca0dfc3593c57a3
|
4
|
+
data.tar.gz: 5502f9355320e6e1031ba5c899e9f9fde2e64ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c33ccd32d999894c4fd7f32ec83624ff8531c73113118ce1d09146b1c746d843e17487a5fdecacb49cb45ce99efc00908b75759a170fc7bc2464a18a278a43
|
7
|
+
data.tar.gz: dbe113b6f61a0568538e52d7fecb99ffb6dab72e0284e0c5a230843a6c4191cc2da78fa737176b7718321c574649408f7de07f512cd3c78c6f39707416c423f8
|
data/README.md
CHANGED
@@ -3,21 +3,27 @@
|
|
3
3
|
[MapPLZ](http://mapplz.com) is a framework to make mapping quick and easy in
|
4
4
|
your favorite language.
|
5
5
|
|
6
|
+
<img src="https://raw.githubusercontent.com/mapmeld/mapplz-ruby/master/logo.jpg" width="140"/>
|
7
|
+
|
6
8
|
## Getting started
|
7
9
|
|
8
|
-
|
10
|
+
MapPLZ consumes many many types of geodata. It can process data for a script or dump
|
11
|
+
it into a database.
|
12
|
+
|
13
|
+
Here's how you can add some data:
|
9
14
|
|
10
15
|
```
|
11
16
|
mapstore = MapPLZ.new
|
12
17
|
|
13
18
|
# a point
|
14
19
|
mapstore << [lat, lng]
|
15
|
-
mapstore
|
20
|
+
mapstore << { lat: 40, lng: -70 }
|
21
|
+
mapstore.add( [lng, lat], lonlat: true )
|
16
22
|
|
17
23
|
# multiple points
|
18
24
|
mapstore << [point1, point2]
|
19
25
|
|
20
|
-
# a line or
|
26
|
+
# a line or polygon
|
21
27
|
mapstore << [[point1, point2, point3]]
|
22
28
|
mapstore << [[point1, point2, point3, point1]]
|
23
29
|
mapstore << { path: [point1, point2], label: 'hello world' }
|
@@ -41,9 +47,22 @@ mapstore << [lat, lng, { color: 'red', cost: 10 }]
|
|
41
47
|
mapstore << { type: "Feature", geometry: { type: "Point", properties: { name: "Bella" }, coordinates: [lng, lat] } }
|
42
48
|
```
|
43
49
|
|
50
|
+
MapPLZ can read GeoJSON files and some CSVs.
|
51
|
+
|
52
|
+
```
|
53
|
+
@mapstore < File.open('test.csv')
|
54
|
+
@mapstore < File.open('test.geojson')
|
55
|
+
```
|
56
|
+
|
57
|
+
If you have gdal installed, you can import files in formats parseable by the ```ogr2ogr``` command line tool.
|
58
|
+
|
59
|
+
```
|
60
|
+
@mapstore < File.open('test.shp')
|
61
|
+
```
|
62
|
+
|
44
63
|
## Export HTML and GeoJSON
|
45
64
|
|
46
|
-
You can output the
|
65
|
+
You can output the entire dataset anytime as GeoJSON:
|
47
66
|
|
48
67
|
```
|
49
68
|
@mapper = MapPLZ.new
|
@@ -69,7 +88,7 @@ require 'mapplz'
|
|
69
88
|
@mapper.render_html
|
70
89
|
```
|
71
90
|
|
72
|
-
This
|
91
|
+
This extends the Leaflet-Rails plugin. Set Leaflet defaults directly:
|
73
92
|
|
74
93
|
```
|
75
94
|
Leaflet.tile_layer = 'http://{s}.somedomain.com/blabla/{z}/{x}/{y}.png'
|
@@ -82,7 +101,7 @@ You can pass options to render_html, including new default styles for lines and
|
|
82
101
|
@mapper.render_html(max_zoom: 18, fillColor: '#00f')
|
83
102
|
```
|
84
103
|
|
85
|
-
You can also add styles
|
104
|
+
You can also add styles as you enter data into MapPLZ.
|
86
105
|
|
87
106
|
```
|
88
107
|
@mapper << { path: [point1, point2], color: 'red', opacity: 0.8 }
|
@@ -126,24 +145,10 @@ my_features = @mapper.where('points > 10')
|
|
126
145
|
collection = { type: 'FeatureCollection', features: my_features.map { |feature| JSON.parse(feature.to_geojson) } }
|
127
146
|
```
|
128
147
|
|
129
|
-
## Files
|
130
|
-
|
131
|
-
MapPLZ can be passed a CSV or GeoJSON file.
|
132
|
-
|
133
|
-
```
|
134
|
-
@mapstore < File.open('test.csv')
|
135
|
-
@mapstore < File.open('test.geojson')
|
136
|
-
```
|
137
|
-
|
138
|
-
If you have gdal installed, you can import files in most formats parseable by the ```ogr2ogr``` command line tool.
|
139
|
-
|
140
|
-
```
|
141
|
-
@mapstore < File.open('test.shp')
|
142
|
-
```
|
143
|
-
|
144
148
|
## Databases
|
145
149
|
|
146
|
-
|
150
|
+
If you want to store geodata in a database, you can use Postgres/PostGIS or MongoDB.
|
151
|
+
SQLite/Spatialite support is written but untested.
|
147
152
|
|
148
153
|
MapPLZ simplifies geodata management and queries.
|
149
154
|
|
@@ -154,9 +159,10 @@ mapplz.choose_db('postgis')
|
|
154
159
|
```
|
155
160
|
|
156
161
|
```
|
157
|
-
#
|
162
|
+
# updating records
|
158
163
|
pt = mapstore << [lat, lng]
|
159
|
-
pt
|
164
|
+
pt[:name] = "Sears Tower"
|
165
|
+
pt[:lat] += 1
|
160
166
|
pt.save!
|
161
167
|
pt.delete_item
|
162
168
|
```
|
@@ -180,7 +186,7 @@ conn.exec('CREATE TABLE mapplz (id SERIAL PRIMARY KEY, label VARCHAR(30), geom p
|
|
180
186
|
mapstore = MapPLZ.new(conn)
|
181
187
|
mapstore.choose_db('postgis')
|
182
188
|
|
183
|
-
# Spatialite
|
189
|
+
# Spatialite (written but untested)
|
184
190
|
require 'sqlite3'
|
185
191
|
db = SQLite3::Database.new('data/mapplz.sqlite')
|
186
192
|
db.execute(".load 'libspatialite.so'")
|
data/lib/mapplz.rb
CHANGED
@@ -433,6 +433,14 @@ class MapPLZ
|
|
433
433
|
# assume user properties are an ordered array of values known to the user
|
434
434
|
user_properties = user_geo.drop(2)
|
435
435
|
|
436
|
+
# only one property and it's a string? check for JSON hash
|
437
|
+
if user_properties.length == 1 && user_properties[0].is_a?(String)
|
438
|
+
begin
|
439
|
+
user_properties[0] = JSON.parse(user_properties[0])
|
440
|
+
rescue
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
436
444
|
# only one property and it's a hash? it's a hash of properties
|
437
445
|
if user_properties.length == 1 && user_properties[0].is_a?(Hash)
|
438
446
|
user_properties[0].keys.each do |key|
|