Sha256: 5efb84c1c660c8fa8b479b95bd73b7fd41b40c010bf3e11fa7fd8c8215480176

Contents?: true

Size: 847 Bytes

Versions: 44

Compression:

Stored size: 847 Bytes

Contents

require 'ostruct'
require 'digest/md5'

module SpatialFeatures
  module Importers
    class JsonArcGIS < Base
      def cache_key
        @cache_key ||= Digest::MD5.hexdigest(features.to_json)
      end

      private

      def each_record(&block)
        json = esri_json_to_geojson(@data)
        json['features'].each do |record|
          yield OpenStruct.new(
            :feature_type => record['geometry']['type'],
            :geog => geom_from_json(record['geometry']),
            :metadata => record['properties']
          )
        end
      end

      def esri_json_to_geojson(url)
        JSON.parse(`ogr2ogr -f GeoJSON /dev/stdout "#{url}" OGRGeoJSON`)
      end

      def geom_from_json(geometry)
        ActiveRecord::Base.connection.select_value("SELECT ST_GeomFromGeoJSON('#{geometry.to_json}')")
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
spatial_features-2.17.2 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.17.1 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.17.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.16.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.15.1 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.15.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.14.1 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.14.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.13.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.12.3 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.12.2 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.12.1 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.12.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.11.1 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.11.0 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.10.9 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.10.8 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.10.7 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.10.6 lib/spatial_features/importers/json_arcgis.rb
spatial_features-2.10.5 lib/spatial_features/importers/json_arcgis.rb