sabman (owner)

Revisions

gist: 226653 Download_button fork
public
Description:
gml_helper.rb
Public Clone URL: git://gist.github.com/226653.git
Embed All Files: show embed
gml_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'rubygems'
require 'geo_ruby'
include GeoRuby::SimpleFeatures
module GmlHelper
 
  def parse_gml(gml_str)
    doc = Hpricot(gml_str)
    coords = doc.search('gml:coordinates').inner_html.split(',')
    unless coords.empty? or coords.nil?
      if doc.search("gml:point").size == 1
        #Hpricot('<gml:Point srsName="SDO:8311" xmlns:gml="http://www.opengis.net/gml"><gml:coordinates decimal="." cs="," ts=" ">111.733,-15.783, </gml:coordinates></gml:Point>')
        point = Point.from_x_y(coords[0], coords[1])
        point.as_wkt
      elsif doc.search("gml:linestring").size == 1
        #Hpricot('<gml:LineString srsName="SDO:8311" xmlns:gml="http://www.opengis.net/gml"><gml:coordinates decimal="." cs="," ts=" ">128.62768333,-33.64501667, 128.6114,-33.64481667, </gml:coordinates></gml:LineString>')
        coords.delete_at(coords.size-1)
        linecoords = []
        (0..(coords.size/2)-1).each{ |i| linecoords << [coords[i*2].to_f, coords[i*2+1].to_f]}
        linestring = LineString.from_coordinates(linecoords)
        linestring.as_wkt
      end
    else
      raise "Unsupported GML Geomtry"
    end
  end
  
end