spatial_features 2.7.6 → 2.7.7
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 +24 -7
- data/lib/spatial_features/importers/file.rb +1 -1
- data/lib/spatial_features/importers/shapefile.rb +18 -9
- data/lib/spatial_features/unzip.rb +1 -1
- data/lib/spatial_features/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1569586b460b18ee4a83871a3af3c5b4d8b54a5fbe84d9a4f1b3a191658a31f
|
4
|
+
data.tar.gz: d69c1f4fa29bd3b6b15770a59af3821521942723091def5945b6c065454ace5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9042d3ef062b8662697970fe58715b27d69bdc46acead5d030697b4461ee25b06ad9afd0b6b03ebbba57b4f93e89cebe7278da5a9897b1e42f7c9135dbeb59
|
7
|
+
data.tar.gz: b64e7d40f30753e25be1d5be07b7b7261b72def8ca3eaffa622541386a772c5d39bdda7b94c70922ea9bebbb833bc292ea15dd4b5bf08c8796457f22fea4d5f8
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Adds spatial methods to a model.
|
|
21
21
|
execute("
|
22
22
|
CREATE EXTENSION hstore;
|
23
23
|
CREATE EXTENSION postgis;
|
24
|
-
|
24
|
+
|
25
25
|
CREATE TABLE features (
|
26
26
|
id integer NOT NULL,
|
27
27
|
spatial_model_type character varying(255),
|
@@ -42,12 +42,12 @@ Adds spatial methods to a model.
|
|
42
42
|
centroid geography,
|
43
43
|
kml_centroid text
|
44
44
|
);
|
45
|
-
|
45
|
+
|
46
46
|
CREATE SEQUENCE features_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
|
47
47
|
ALTER SEQUENCE features_id_seq OWNED BY features.id;
|
48
48
|
ALTER TABLE ONLY features ALTER COLUMN id SET DEFAULT nextval('features_id_seq'::regclass);
|
49
49
|
ALTER TABLE ONLY features ADD CONSTRAINT features_pkey PRIMARY KEY (id);
|
50
|
-
|
50
|
+
|
51
51
|
CREATE INDEX index_features_on_feature_type ON features USING btree (feature_type);
|
52
52
|
CREATE INDEX index_features_on_spatial_model_id_and_spatial_model_type ON features USING btree (spatial_model_id, spatial_model_type);
|
53
53
|
CREATE INDEX index_features_on_geom ON features USING gist (geom);
|
@@ -63,12 +63,12 @@ Adds spatial methods to a model.
|
|
63
63
|
intersection_cache_distance double precision,
|
64
64
|
features_hash character varying(255)
|
65
65
|
);
|
66
|
-
|
66
|
+
|
67
67
|
CREATE SEQUENCE spatial_caches_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
|
68
68
|
ALTER SEQUENCE spatial_caches_id_seq OWNED BY spatial_caches.id;
|
69
69
|
ALTER TABLE ONLY spatial_caches ALTER COLUMN id SET DEFAULT nextval('spatial_caches_id_seq'::regclass);
|
70
70
|
ALTER TABLE ONLY spatial_caches ADD CONSTRAINT spatial_caches_pkey PRIMARY KEY (id);
|
71
|
-
|
71
|
+
|
72
72
|
CREATE INDEX index_spatial_caches_on_spatial_model ON spatial_caches USING btree (spatial_model_id, spatial_model_type);
|
73
73
|
|
74
74
|
CREATE TABLE spatial_proximities (
|
@@ -80,12 +80,12 @@ Adds spatial methods to a model.
|
|
80
80
|
distance_in_meters double precision,
|
81
81
|
intersection_area_in_square_meters double precision
|
82
82
|
);
|
83
|
-
|
83
|
+
|
84
84
|
CREATE SEQUENCE spatial_proximities_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
|
85
85
|
ALTER SEQUENCE spatial_proximities_id_seq OWNED BY spatial_proximities.id;
|
86
86
|
ALTER TABLE ONLY spatial_proximities ALTER COLUMN id SET DEFAULT nextval('spatial_proximities_id_seq'::regclass);
|
87
87
|
ALTER TABLE ONLY spatial_proximities ADD CONSTRAINT spatial_proximities_pkey PRIMARY KEY (id);
|
88
|
-
|
88
|
+
|
89
89
|
CREATE INDEX index_spatial_proximities_on_model_a ON spatial_proximities USING btree (model_a_id, model_a_type);
|
90
90
|
CREATE INDEX index_spatial_proximities_on_model_b ON spatial_proximities USING btree (model_b_id, model_b_type);
|
91
91
|
")
|
@@ -120,3 +120,20 @@ class Location < ActiveRecord::Base
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
```
|
123
|
+
|
124
|
+
### SpatialFeatures::Importers::Shapefile
|
125
|
+
|
126
|
+
#### Default Options
|
127
|
+
|
128
|
+
Default options can be specified on the Shapefile importer class itself.
|
129
|
+
|
130
|
+
- ##### default_proj4_projection
|
131
|
+
A proj4 formatted projection string to use when no other projection has been specified either in the shapefile or the
|
132
|
+
importer instance.
|
133
|
+
|
134
|
+
Example:
|
135
|
+
```ruby
|
136
|
+
SpatialFeatures::Importers::Shapefile.default_proj4_projection = "+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
|
137
|
+
```
|
138
|
+
|
139
|
+
Default: `nil`
|
@@ -4,7 +4,7 @@ module SpatialFeatures
|
|
4
4
|
module Importers
|
5
5
|
class File < SimpleDelegator
|
6
6
|
def initialize(data, *args)
|
7
|
-
file = Download.open(data, unzip:
|
7
|
+
file = Download.open(data, unzip: [/\.kml$/, /\.shp$/])
|
8
8
|
|
9
9
|
case ::File.extname(file.path.downcase)
|
10
10
|
when '.kml'
|
@@ -4,6 +4,8 @@ require 'digest/md5'
|
|
4
4
|
module SpatialFeatures
|
5
5
|
module Importers
|
6
6
|
class Shapefile < Base
|
7
|
+
class_attribute :default_proj4_projection
|
8
|
+
|
7
9
|
def initialize(data, *args, proj4: nil, **options)
|
8
10
|
super(data, *args, **options)
|
9
11
|
@proj4 = proj4
|
@@ -16,24 +18,22 @@ module SpatialFeatures
|
|
16
18
|
private
|
17
19
|
|
18
20
|
def each_record(&block)
|
19
|
-
file = Download.open(@data, unzip: '.shp')
|
20
|
-
|
21
|
-
if !@proj4
|
22
|
-
@proj4 = proj4_from_file(file)
|
23
|
-
end
|
24
|
-
|
25
21
|
RGeo::Shapefile::Reader.open(file.path) do |records|
|
26
22
|
records.each do |record|
|
27
|
-
yield OpenStruct.new data_from_wkt(record.geometry.as_text,
|
23
|
+
yield OpenStruct.new data_from_wkt(record.geometry.as_text, proj4_projection).merge(:metadata => record.attributes) if record.geometry.present?
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
31
27
|
|
32
|
-
def
|
28
|
+
def proj4_projection
|
29
|
+
@proj4 ||= proj4_from_file || default_proj4_projection || raise(IndeterminateProjection, 'Could not determine shapefile projection. Check that `gdalsrsinfo` is installed.')
|
30
|
+
end
|
31
|
+
|
32
|
+
def proj4_from_file
|
33
33
|
# Sanitize: "'+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs '\n" and lately
|
34
34
|
# "+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs \n" to
|
35
35
|
# "+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs"
|
36
|
-
`gdalsrsinfo "#{file.path}" -o proj4`.strip.remove(/^'|'$/).presence
|
36
|
+
`gdalsrsinfo "#{file.path}" -o proj4`.strip.remove(/^'|'$/).presence
|
37
37
|
end
|
38
38
|
|
39
39
|
def data_from_wkt(wkt, proj4)
|
@@ -41,6 +41,15 @@ module SpatialFeatures
|
|
41
41
|
SELECT ST_Transform(ST_GeomFromText('#{wkt}'), '#{proj4}', 4326) AS geog, GeometryType(ST_GeomFromText('#{wkt}')) AS feature_type
|
42
42
|
SQL
|
43
43
|
end
|
44
|
+
|
45
|
+
def file
|
46
|
+
@file ||= Download.open(@data, unzip: /\.shp$/)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# ERRORS
|
51
|
+
|
52
|
+
class IndeterminateProjection < StandardError; end
|
44
53
|
end
|
45
54
|
end
|
46
55
|
end
|
@@ -6,7 +6,7 @@ module SpatialFeatures
|
|
6
6
|
paths = extract(file_path)
|
7
7
|
|
8
8
|
if find = Array.wrap(find).presence
|
9
|
-
paths = paths.detect {|path| find.any? {|pattern| path.
|
9
|
+
paths = paths.detect {|path| find.any? {|pattern| path.index(pattern) } }
|
10
10
|
raise(ImportError, "No file matched #{find}") unless paths.present?
|
11
11
|
end
|
12
12
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spatial_features
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Wallace
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-07-
|
12
|
+
date: 2019-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.7.
|
221
|
+
rubygems_version: 2.7.9
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Adds spatial methods to a model.
|