Skip to content

Commit 1e868fa

Browse files
author
Stephanie Reeder
committed
merging
2 parents a671b4f + caa32d9 commit 1e868fa

File tree

7 files changed

+223
-121
lines changed

7 files changed

+223
-121
lines changed

requirements.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
six
22
sqlalchemy
3-
geoalchemy2
3+
geoalchemy
4+
Change line #242 in geoalchemy/base.py
5+
from:
6+
class SpatialComparator(ColumnProperty.ColumnComparator):
7+
to :
8+
class SpatialComparator(ColumnProperty.Comparator):
9+
10+
shapely
411

512
matplotlib
613
dateutils

src/Examples/Sample.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#connect to database
2323
#createconnection (dbtype, servername, dbname, username, password)
2424
#session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
25-
session_factory = dbconnection.createConnection('mysql', 'jws.uwrl.usu.edu', 'odm2', 'ODM', 'ODM123!!', 2)
25+
session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/DBs/ODM2.sqlite', 2.0)
2626
# session_factory= dbconnection.createConnection('mssql')
2727

2828

@@ -49,7 +49,13 @@
4949
for x in allPeople:
5050
print x.PersonFirstName + " " + x.PersonLastName
5151

52-
52+
try:
53+
print "\n-------- Information about an Affiliation ---------"
54+
allaff = read.getAllAffiliations()
55+
for x in allaff:
56+
print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)
57+
except Exception as e:
58+
print "Unable to demo getAllAffiliations", e
5359

5460
# Get all of the SamplingFeatures from the database that are Sites
5561
try:
@@ -93,7 +99,7 @@
9399
newsf.SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV
94100
newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
95101
session.add(newsf)
96-
session.commit()
102+
#session.commit()
97103
print "new sampling feature added to database", newsf
98104

99105
except Exception as e :

src/api/ODM2/apiCustomType.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from sqlalchemy import func
2-
from sqlalchemy.sql.expression import FunctionElement
3-
from sqlalchemy.types import UserDefinedType
2+
from sqlalchemy.sql.expression import FunctionElement, ClauseElement, Executable
3+
#from sqlalchemy.types import UserDefinedType
44
from sqlalchemy.ext.compiler import compiles
55

66

@@ -9,13 +9,17 @@
99
# function to pull from the database
1010
def compiles_as_bound(cls):
1111

12+
@compiles(cls)
13+
def compile_function(element, compiler, **kw):
14+
return None
15+
1216
@compiles(cls, 'postgresql')
1317
def compile_function(element, compiler, **kw):
1418
val = "%s(%s)"%(element.name, compiler.process(element.clauses.clauses[0]))
1519
#ST_AsText("\"ODM2\".\"SamplingFeatures\".\"FeatureGeometry\"")
1620
return val
1721

18-
@compiles(cls)#, 'mysql')
22+
@compiles(cls, 'mysql')
1923
def compile_function(element, compiler, **kw):
2024
val="%s(%s)"%(element.name.lower().split('_')[1], compiler.process(element.clauses.clauses[0]))
2125
#astext("`ODM2`.`SamplingFeatures`.`FeatureGeometry`")
@@ -24,12 +28,15 @@ def compile_function(element, compiler, **kw):
2428

2529
@compiles(cls, 'sqlite')
2630
def compile_function(element, compiler, **kw):
27-
return "%s(%s)"%(element.name.split('_')[-1], compiler.process(element.clauses.clauses[0]))
28-
#return ST_AsText(samplingfeatures.featuregeometry)
31+
#ST_AsText(samplingfeatures.featuregeometry)
32+
#assuming the user is using spatialite
33+
#return "%s(%s)"%(element.name.split('_')[-1], compiler.process(element.clauses.clauses[0]))
34+
#what if user does not have a spatial db?
35+
return "%s"%compiler.process(element.clauses.clauses[0])
2936

3037
@compiles(cls, 'mssql')
3138
def compile_function(element, compiler, **kw):
32-
#[SamplingFeatures_1].[FeatureGeometry].STAsText()
39+
#[SamplingFeatures].[FeatureGeometry].STAsText()
3340
return "%s.%s()" % (compiler.process(element.clauses.clauses[0]), element.name.replace('_', '') )
3441

3542
return cls
@@ -55,23 +62,30 @@ def compile_function(element, compiler, **kw):
5562
# GeomFromText("POINT(30 10)")
5663
# GeomFromText(:featuregeometry)
5764

58-
val = "%s(%s)"%(name, element.clauses.clauses[0])
65+
val = "%s(%s)"%(name, compiler.process(element.bindelement))
5966
return val
6067

6168
@compiles(cls, 'sqlite')
6269
def compile_function(element, compiler, **kw):
6370
name= element.name.split('_')[-1]
6471
#return "%s(%s)" % (element.name.replace('_', ''), "'POINT (30 10)'")
72+
#assuming the user is using spatialite
73+
#return "%s(%s)"%(name, "'POINT(30 10)'")
6574

66-
return "%s(%s)"%(name, "'POINT(30 10)'")
75+
#what if user does not have a spatial?
76+
# >>> self.bindtemplate
77+
# '?'
78+
# (BindParameter('featuregeometry', None, type_=Geometry()),)
79+
# >>> dialect.paramstyle
80+
#print compiler.bindtemplate
81+
return "%s(%s)"%(name, '')
6782

6883
@compiles(cls, 'mssql')
6984
def compile_function(element, compiler, **kw):
7085
#return "Geometry::%s(%s, 0)"%(element.name.replace('_', ''), "'POINT (30 10)'")
7186
name = "Geometry::%s" % element.name.replace('_', '')
72-
return "%s(%s,0)"%(name, "'POINT(30 10)'")
73-
7487

88+
return "%s(%s,0)"%(name, "'POINT(30 10)'")
7589

7690
return cls
7791

@@ -81,6 +95,8 @@ def compile_function(element, compiler, **kw):
8195
class ST_GeomFromText(FunctionElement):
8296
name = "ST_GeomFromText"
8397

98+
99+
84100
@compiles_as_bound
85101
class ST_AsText(FunctionElement):
86102
name = 'ST_AsText'
@@ -89,7 +105,8 @@ class ST_AsText(FunctionElement):
89105
class ST_AsBinary(FunctionElement):
90106
name = 'ST_AsBinary'
91107

92-
from sqlalchemy import String, type_coerce
108+
109+
93110
class Geometry(GeometryBase):
94111

95112
def column_expression(self, col):
@@ -99,21 +116,17 @@ def column_expression(self, col):
99116
return value
100117

101118
def bind_expression(self, bindvalue):
102-
103-
#mysql, sqlite
119+
val = None
120+
# mysql, sqlite
104121
val = func.GeomFromText(bindvalue, type_=self)
105122

106-
#postgresql
107-
#val = func.ST_GeomFromText(bindvalue, type_=self)
108-
#mssql
123+
# postgresql
124+
# val = func.ST_GeomFromText(bindvalue, type_=self)
125+
# mssql
109126
if val is None:
110127
val = ST_GeomFromText(bindvalue, type_=self)
111128
return val
112129

113130

114131

115132

116-
117-
118-
119-

0 commit comments

Comments
 (0)