Created
November 22, 2009 11:20
-
-
Save sabman/240530 to your computer and use it in GitHub Desktop.
test_crud_sdo_geometry.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'schema_dev.rb' | |
require '../utils/sdo_geometry.rb' | |
include GeoRuby::SimpleFeatures | |
ProdDb.connection.execute("ALTER SESSION set NLS_DATE_FORMAT ='DD-MON-FXYYYY'") | |
params = { | |
:eno=>455129, | |
:sampleid=>'GA2476/006CAM002', | |
:geom_original => nil, | |
:start_lat=>-28.36372, | |
:start_long=>112.88068, | |
:start_depth=>906, | |
:end_lat=>-28.34687, | |
:end_long=>112.86782, | |
:end_depth=>1866, | |
:acquiredate=>'02-NOV-2008', | |
:ano=>84, | |
:activity_code=>'A', | |
:access_code =>'A', | |
:sample_type=>'UNDER WATER CAMERA', | |
:origno => 641 | |
} | |
def convert_params_spatial_values_to_georuby(h) | |
geom = nil | |
r = h | |
if h[:start_lat] # linestring | |
if r[:start_depth] | |
geom = LineString.from_coordinates( [[r[:start_long], r[:start_lat],r[:start_depth]],[r[:end_long], r[:end_lat], r[:end_depth]]], 8311, true) | |
else | |
geom = LineString.from_coordinates([[r[:start_long], r[:start_lat]], [r[:end_long], r[:end_lat]]], 8311) | |
end | |
r.delete(:start_long) | |
r.delete(:start_lat) | |
r.delete(:end_long) | |
r.delete(:end_lat) | |
r.delete(:start_depth) | |
r.delete(:end_depth) | |
elsif h[:lat] # point | |
if r[:depth] | |
geom = Point.from_coordinates([r[:long], r[:lat], r[:depth]], 8311, true) | |
else | |
geom = Point.from_coordinates([r[:long], r[:lat]], 8311) | |
end | |
r.delete(:long) | |
r.delete(:lat) | |
r.delete(:depth) | |
end | |
r[:geom_original] = geom | |
r | |
end | |
@params = convert_params_spatial_values_to_georuby(params) | |
s = Prod::Sample.new(@params) | |
s.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment