spatial_features 2.10.6 → 2.11.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c14269424ac2b30935b7f291f51080271e0932c400036bf5156223325ead8ba
|
4
|
+
data.tar.gz: d715d47e9dfa87eee07e01bc71b03dc9af5ceb6415552f24663eef9a8d81bda6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b7fef2ae89493b544b46896136bddcd59afc470db34be530c2763cede9dca82082c695056583aa7665f03dab0c21f87d16429cc37d74682cf9ac984956c83cb
|
7
|
+
data.tar.gz: 16bc0f99d7249a85f0c48e07f0b9dd5b02058fa307c4eea20142dedf6e695b9c035528d26b26c22dc9ec420247d36a4f8476f8e5b5a0fe865bac68650d64ecfb
|
@@ -40,6 +40,11 @@ class AbstractFeature < ActiveRecord::Base
|
|
40
40
|
where(:feature_type => 'point')
|
41
41
|
end
|
42
42
|
|
43
|
+
def self.within_distance(lat, lng, distance_in_meters)
|
44
|
+
# where("ST_DWithin(features.geog, ST_SetSRID( ST_Point( -71.104, 42.315), 4326)::geography, :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
|
45
|
+
where("ST_DWithin(features.geog, ST_Point(:lng, :lat), :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
|
46
|
+
end
|
47
|
+
|
43
48
|
def self.area_in_square_meters(geom = 'geom_lowres')
|
44
49
|
current_scope = all.polygons
|
45
50
|
unscoped { connection.select_value(select("ST_Area(ST_Union(#{geom}))").from(current_scope, :features)).to_f }
|
@@ -131,7 +131,7 @@ module SpatialFeatures
|
|
131
131
|
scope = scope.select(options[:columns])
|
132
132
|
|
133
133
|
scope = scope.select("ST_Distance(features.geom, other_features.geom) AS distance_in_meters") if options[:distance]
|
134
|
-
scope = scope.select("ST_Area(ST_Intersection(features.geom, other_features.geom)) AS intersection_area_in_square_meters") if options[:intersection_area]
|
134
|
+
scope = scope.select("ST_Area(ST_Intersection(ST_CollectionExtract(features.geom, 3), ST_CollectionExtract(other_features.geom, 3))) AS intersection_area_in_square_meters") if options[:intersection_area] # Use ST_CollectionExtract to avoid a segfault we've been seeing when intersecting certain geometry
|
135
135
|
|
136
136
|
return scope
|
137
137
|
end
|
@@ -142,9 +142,11 @@ module SpatialFeatures
|
|
142
142
|
scope = features_scope(self).select("#{geom} AS geom").select(:spatial_model_id)
|
143
143
|
|
144
144
|
other_scope = features_scope(other).select("ST_Union(#{geom}) AS geom")
|
145
|
-
|
146
145
|
return joins(%Q(INNER JOIN (#{scope.to_sql}) AS #{table_alias} ON #{table_alias}.spatial_model_id = #{table_name}.id))
|
147
|
-
.joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias}
|
146
|
+
.joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias}
|
147
|
+
ON NOT ST_IsEmpty(#{table_alias}.geom) -- Can't ST_DWithin empty geometry
|
148
|
+
AND NOT ST_IsEmpty(#{other_alias}.geom) -- Can't ST_DWithin empty geometry
|
149
|
+
AND ST_DWithin(#{table_alias}.geom, #{other_alias}.geom, #{buffer})))
|
148
150
|
end
|
149
151
|
|
150
152
|
def features_scope(other)
|
@@ -181,7 +183,7 @@ module SpatialFeatures
|
|
181
183
|
end
|
182
184
|
|
183
185
|
def intersects?(other)
|
184
|
-
self.class.intersecting(other).exists?(
|
186
|
+
self.class.unscoped { self.class.intersecting(other).exists?(id) }
|
185
187
|
end
|
186
188
|
|
187
189
|
def total_intersection_area_percentage(klass)
|
@@ -6,22 +6,24 @@ module SpatialFeatures
|
|
6
6
|
private
|
7
7
|
|
8
8
|
def each_record(&block)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
yield OpenStruct.new(:feature_type => sql_type, :geog => geom_from_kml(placemark), :name => name, :metadata => metadata)
|
9
|
+
{'Polygon' => 'POLYGON', 'LineString' => 'LINE', 'Point' => 'POINT'}.each do |kml_type, sql_type|
|
10
|
+
Nokogiri::XML(@data).css(kml_type).each do |feature|
|
11
|
+
if placemark = feature.ancestors('Placemark').first
|
12
|
+
name = placemark.css('name').text
|
13
|
+
metadata = extract_metadata(placemark)
|
14
|
+
else
|
15
|
+
metadata = {}
|
18
16
|
end
|
17
|
+
|
18
|
+
next if blank_feature?(feature)
|
19
|
+
|
20
|
+
yield OpenStruct.new(:feature_type => sql_type, :geog => geom_from_kml(feature), :name => name, :metadata => metadata)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
24
|
-
|
25
|
+
def blank_feature?(feature)
|
26
|
+
feature.css('coordinates').text.blank?
|
25
27
|
end
|
26
28
|
|
27
29
|
def geom_from_kml(kml)
|
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.
|
4
|
+
version: 2.11.1
|
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: 2020-
|
12
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|