]> git.openstreetmap.org Git - rails.git/blobdiff - lib/osm.rb
Potlatch 0.7b: small bugfixes
[rails.git] / lib / osm.rb
index 6e9346bb4f0076df8361c9a52b52348a8a426747..bd935102658576295b2670ca46a8b28de89e94b4 100644 (file)
@@ -1,13 +1,6 @@
+# The OSM module provides support functions for OSM.
 module OSM
 
-  # This piece of magic reads a GPX with SAX and spits out
-  # lat/lng and stuff
-  #
-  # This would print every latitude value:
-  #
-  # gpx = OSM::GPXImporter.new('somefile.gpx')
-  # gpx.points {|p| puts p['latitude']}
-
   require 'time'
   require 'rexml/parsers/sax2parser'
   require 'rexml/text'
@@ -15,11 +8,27 @@ module OSM
   require 'digest/md5'
   require 'RMagick'
 
+  # The base class for API Errors.
+  class APIError < RuntimeError
+  end
+
+  # Raised when an API object is not found.
+  class APINotFoundError < APIError
+  end
+
+  # Raised when a precondition to an API action fails sanity check.
+  class APIPreconditionFailedError < APIError
+  end
+
+  # Raised when to delete an already-deleted object.
+  class APIAlreadyDeletedError < APIError
+  end
+
+  # Helper methods for going to/from mercator and lat/lng.
   class Mercator
     include Math
 
     #init me with your bounding box and the size of your image
-
     def initialize(min_lat, min_lon, max_lat, max_lon, width, height)
       xsize = xsheet(max_lon) - xsheet(min_lon)
       ysize = ysheet(max_lat) - ysheet(min_lat)
@@ -62,6 +71,13 @@ module OSM
   end
 
 
+  # This piece of magic reads a GPX with SAX and spits out
+  # lat/lng and stuff
+  #
+  # This would print every latitude value:
+  #
+  # gpx = OSM::GPXImporter.new('somefile.gpx')
+  # gpx.points {|p| puts p['latitude']}
   class GPXImporter
     # FIXME swap REXML for libXML
     attr_reader :possible_points
@@ -279,7 +295,7 @@ module OSM
     def initialize(feed_title='OpenStreetMap GPS Traces', feed_description='OpenStreetMap GPS Traces', feed_url='http://www.openstreetmap.org/traces/')
       @doc = XML::Document.new
       @doc.encoding = 'UTF-8' 
-      
+
       rss = XML::Node.new 'rss'
       @doc.root = rss
       rss['version'] = "2.0"
@@ -425,72 +441,5 @@ module OSM
     return "#{tilesql} AND #{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}"
   end
 
-  class Potlatch # crazy shit
-
-    # ----- getpresets
-    #            in:   none
-    #            does: reads tag preset menus, colours, and autocomplete config files
-    #        out:  [0] presets, [1] presetmenus, [2] presetnames,
-    #                          [3] colours, [4] casing, [5] areas, [6] autotags
-    #                          (all hashes)
-    def self.get_presets
-      RAILS_DEFAULT_LOGGER.info("  Message: getpresets")
-
-      # Read preset menus
-      presets={}
-      presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]; presetmenus['POI']=[]
-      presetnames={}; presetnames['point']={}; presetnames['way']={}; presetnames['POI']={}
-      presettype=''
-      presetcategory=''
-      #        StringIO.open(txt) do |file|
-      File.open("#{RAILS_ROOT}/config/potlatch/presets.txt") do |file|
-        file.each_line {|line|
-          t=line.chomp
-          if (t=~/(\w+)\/(\w+)/) then
-            presettype=$1
-            presetcategory=$2
-            presetmenus[presettype].push(presetcategory)
-            presetnames[presettype][presetcategory]=["(no preset)"]
-          elsif (t=~/^(.+):\s?(.+)$/) then
-            pre=$1; kv=$2
-            presetnames[presettype][presetcategory].push(pre)
-            presets[pre]={}
-            kv.split(',').each {|a|
-              if (a=~/^(.+)=(.*)$/) then presets[pre][$1]=$2 end
-            }
-          end
-        }
-      end
-
-      # Read colours/styling
-      colours={}; casing={}; areas={}
-      File.open("#{RAILS_ROOT}/config/potlatch/colours.txt") do |file|
-        file.each_line {|line|
-          t=line.chomp
-          if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
-            tag=$1
-            if ($2!='-') then colours[tag]=$2.hex end
-            if ($3!='-') then casing[tag]=$3.hex end
-            if ($4!='-') then areas[tag]=$4.hex end
-          end
-        }
-      end
-
-      # Read auto-complete
-      autotags={}; autotags['point']={}; autotags['way']={}; autotags['POI']={};
-      File.open("#{RAILS_ROOT}/config/potlatch/autocomplete.txt") do |file|
-        file.each_line {|line|
-          t=line.chomp
-          if (t=~/^(\w+)\/(\w+)\s+(.+)$/) then
-            tag=$1; type=$2; values=$3
-            if values=='-' then autotags[type][tag]=[]
-            else autotags[type][tag]=values.split(',').sort.reverse end
-          end
-        }
-      end
-
-      [presets,presetmenus,presetnames,colours,casing,areas,autotags]
-    end
-  end
 
 end