module XData
factory = RGeo::Geographic.projected_factory(:projection_proj4 => '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs ') rd_factory = RGeo::Geographic.spherical_factory(:srid => 28992, :proj4 => amersfoort-rd-new) curved_factory = RGeo::Geographic.spherical_factory(:srid => 4326)
Constants
- LL_P
- RD_P
- VERSION
Public Class Methods
headers(url)
click to toggle source
# File lib/xdata/util.rb, line 55 def self.headers(url) begin uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) if url.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end return http.head(uri.path.blank? ? "/" : uri.path).to_hash rescue end nil end
parse_json(str)
click to toggle source
# File lib/xdata/util.rb, line 87 def self.parse_json(str) begin return str.blank? ? {} : JSON.parse(str, symbolize_names: true) rescue Exception => e raise XData::Exception.new("#{e.message}; input: #{str}") end end
rd_to_wgs84(x,y)
click to toggle source
# File lib/xdata/util.rb, line 49 def self.rd_to_wgs84(x,y) srcPoint = Proj4::Point.new(x, y) dstPoint = RD_P.transform(LL_P, srcPoint) [dstPoint.lon * (180 / Math::PI), dstPoint.lat * (180 / Math::PI)] end
Public Instance Methods
jsonlog(o)
click to toggle source
for debugging purposes…
# File lib/xdata/util.rb, line 70 def jsonlog(o) STDERR.puts JSON.pretty_generate({ o.class.to_s => o }) end
toPolygon(twopoints)
click to toggle source
# File lib/xdata/util.rb, line 33 def toPolygon(twopoints) lon1 = twopoints[0].lon lat1 = twopoints[0].lat lon2 = twopoints[1].lon lat2 = twopoints[1].lat if lon1.between?(-7000.0,300000.0) and lat1.between?(289000.0,629000.0) # Simple minded check for Dutch new rd system a = XData.rd_to_wgs84(lon1,lat1) lon1 = a[0]; lat1 = a[1] a = XData.rd_to_wgs84(lon2,lat2) lon2 = a[0]; lat2 = a[1] end return { type: 'Polygon', coordinates: [[lon1,lat1], [lon1,lat2], [lon2,lat2], [lon2,lat1], [lon1,lat1]] } end