spatial_features 2.10.5 → 2.11.0
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: fb5268adbbf2c9b9019512e4d3617fc97c587497913202bf95c3dd35332497e8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 37928531494a21c1934425bb222759accdbfae763c7eb2e7f5570e8e17c69e42
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d995ebde69133a39e99885ce694551d5bd64fb08a67b8e658d86138f56673b78a27f101f65cb86027e864d3fa0a3e2c05f43d944a3c55b2fac1a3e53a304715b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 99be0f11815754302e8b3f1cf50fa31964993fa43d2a1cc5a68e688eacb03d0d2116cea1ff71c7c7c8c2c99a7c7ae76c2dc83c0f6bef34ec525434bb990be2e1
         
     | 
| 
         @@ -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 }
         
     | 
| 
         @@ -143,6 +148,10 @@ class AbstractFeature < ActiveRecord::Base 
     | 
|
| 
       143 
148 
     | 
    
         
             
                @make_valid
         
     | 
| 
       144 
149 
     | 
    
         
             
              end
         
     | 
| 
       145 
150 
     | 
    
         | 
| 
      
 151 
     | 
    
         
            +
              def wkt
         
     | 
| 
      
 152 
     | 
    
         
            +
                ActiveRecord::Base.connection.select_value("SELECT ST_ASEWKT('#{geom}')")
         
     | 
| 
      
 153 
     | 
    
         
            +
              end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
       146 
155 
     | 
    
         
             
              private
         
     | 
| 
       147 
156 
     | 
    
         | 
| 
       148 
157 
     | 
    
         
             
              def make_valid
         
     | 
| 
         @@ -81,6 +81,15 @@ module SpatialFeatures 
     | 
|
| 
       81 
81 
     | 
    
         
             
                  end
         
     | 
| 
       82 
82 
     | 
    
         
             
                end
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
      
 84 
     | 
    
         
            +
                def aggregate_features
         
     | 
| 
      
 85 
     | 
    
         
            +
                  type = base_class.to_s # Rails stores polymorphic foreign keys as the base class
         
     | 
| 
      
 86 
     | 
    
         
            +
                  if all == unscoped
         
     | 
| 
      
 87 
     | 
    
         
            +
                    AggregateFeature.where(:spatial_model_type => type)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  else
         
     | 
| 
      
 89 
     | 
    
         
            +
                    AggregateFeature.where(:spatial_model_type => type, :spatial_model_id => all.unscope(:select))
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
       84 
93 
     | 
    
         
             
                # Returns true if the model stores a hash of the features so we don't need to process the features if they haven't changed
         
     | 
| 
       85 
94 
     | 
    
         
             
                def has_spatial_features_hash?
         
     | 
| 
       86 
95 
     | 
    
         
             
                  column_names.include? 'features_hash'
         
     | 
| 
         @@ -131,7 +140,7 @@ module SpatialFeatures 
     | 
|
| 
       131 
140 
     | 
    
         
             
                  scope = scope.select(options[:columns])
         
     | 
| 
       132 
141 
     | 
    
         | 
| 
       133 
142 
     | 
    
         
             
                  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]
         
     | 
| 
      
 143 
     | 
    
         
            +
                  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 
144 
     | 
    
         | 
| 
       136 
145 
     | 
    
         
             
                  return scope
         
     | 
| 
       137 
146 
     | 
    
         
             
                end
         
     | 
| 
         @@ -141,13 +150,12 @@ module SpatialFeatures 
     | 
|
| 
       141 
150 
     | 
    
         
             
                def spatial_join(other, buffer = 0, table_alias = 'features', other_alias = 'other_features', geom = 'geom_lowres')
         
     | 
| 
       142 
151 
     | 
    
         
             
                  scope = features_scope(self).select("#{geom} AS geom").select(:spatial_model_id)
         
     | 
| 
       143 
152 
     | 
    
         | 
| 
       144 
     | 
    
         
            -
                  other_scope = features_scope(other)
         
     | 
| 
       145 
     | 
    
         
            -
                  other_scope_select_sql = "ST_Union(#{geom})"
         
     | 
| 
       146 
     | 
    
         
            -
                  other_scope_select_sql = "ST_Buffer(#{other_scope_select_sql}, #{buffer})" if buffer&.positive?
         
     | 
| 
       147 
     | 
    
         
            -
                  other_scope = other_scope.select("ST_Union(#{geom}) AS geom").select("#{other_scope_select_sql} AS buffered_geom")
         
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
      
 153 
     | 
    
         
            +
                  other_scope = features_scope(other).select("ST_Union(#{geom}) AS geom")
         
     | 
| 
       149 
154 
     | 
    
         
             
                  return joins(%Q(INNER JOIN (#{scope.to_sql}) AS #{table_alias} ON #{table_alias}.spatial_model_id = #{table_name}.id))
         
     | 
| 
       150 
     | 
    
         
            -
                        .joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias} 
     | 
| 
      
 155 
     | 
    
         
            +
                        .joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias}
         
     | 
| 
      
 156 
     | 
    
         
            +
                                   ON NOT ST_IsEmpty(#{table_alias}.geom) -- Can't ST_DWithin empty geometry
         
     | 
| 
      
 157 
     | 
    
         
            +
                                  AND NOT ST_IsEmpty(#{other_alias}.geom) -- Can't ST_DWithin empty geometry
         
     | 
| 
      
 158 
     | 
    
         
            +
                                  AND ST_DWithin(#{table_alias}.geom, #{other_alias}.geom, #{buffer})))
         
     | 
| 
       151 
159 
     | 
    
         
             
                end
         
     | 
| 
       152 
160 
     | 
    
         | 
| 
       153 
161 
     | 
    
         
             
                def features_scope(other)
         
     | 
| 
         @@ -184,7 +192,7 @@ module SpatialFeatures 
     | 
|
| 
       184 
192 
     | 
    
         
             
                end
         
     | 
| 
       185 
193 
     | 
    
         | 
| 
       186 
194 
     | 
    
         
             
                def intersects?(other)
         
     | 
| 
       187 
     | 
    
         
            -
                  self.class.intersecting(other).exists?( 
     | 
| 
      
 195 
     | 
    
         
            +
                  self.class.unscoped { self.class.intersecting(other).exists?(id) }
         
     | 
| 
       188 
196 
     | 
    
         
             
                end
         
     | 
| 
       189 
197 
     | 
    
         | 
| 
       190 
198 
     | 
    
         
             
                def total_intersection_area_percentage(klass)
         
     | 
    
        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.0
         
     | 
| 
       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-01 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rails
         
     |