############################################################################### ## ## ## ALEXANDRIA DIGITAL LIBRARY ## ## University of California at Santa Barbara ## ## ## ## ------------------------------------------------------------------------- ## ## ## ## Copyright (c) 2002 by the Regents of the University of California ## ## All rights reserved ## ## ## ## Redistribution and use in source and binary forms, with or without ## ## modification, are permitted provided that the following conditions are ## ## met: ## ## ## ## 1. Redistributions of source code must retain the above copyright ## ## notice, this list of conditions, and the following disclaimer. ## ## ## ## 2. Redistributions in binary form must reproduce the above copyright ## ## notice, this list of conditions, and the following disclaimer in ## ## the documentation and/or other materials provided with the ## ## distribution. ## ## ## ## 3. All advertising materials mentioning features or use of this ## ## software must display the following acknowledgement: This product ## ## includes software developed by the Alexandria Digital Library, ## ## University of California at Santa Barbara, and its contributors. ## ## ## ## 4. Neither the name of the University nor the names of its ## ## contributors may be used to endorse or promote products derived ## ## from this software without specific prior written permission. ## ## ## ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY ## ## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ## ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE ## ## DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ## ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ## ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ## ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ## ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ## ## ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ## ## POSSIBILITY OF SUCH DAMAGE. ## ## ## ############################################################################### # $Header: /export/home/gjanee/bucket99/paradigms/RCS/Spatial_InformixMapInfo.py,v 1.1 2002/10/22 02:58:09 gjanee Exp $ # SYNOPSIS # # Spatial_InformixMapInfo (table, idColumn, footprintColumn, cardinality) # # table # A table to query, e.g., "holding". # # idColumn # The table's object identifier column (i.e., the column # to be selected), e.g., "holding_id". # # footprintColumn # The table's footprint column (i.e., the column against # which the constraint is to be placed), e.g., # "footprint". # # cardinality # A Cardinality object representing the cardinality of # 'table' with respect to 'footprintColumn'. # # DESCRIPTION # # Translates a spatial constraint to an Informix MapInfo function # call of the form: # # SELECT idColumn FROM table # WHERE function(footprintColumn, targetExpression) # # where 'function' is either 'ST_Contains', 'ST_Within', or # 'ST_Overlaps', depending on the constraint operator. # # This paradigm assumes that MapInfo's first (X) coordinate is # longitude in degrees east of the Greenwich meridian and in the # range [-180,180], and that the second (Y) coordinate is latitude # in degrees north of the equator and in the range [-90,90]. # # 'targetExpression' is a string that can take any of several # forms. Depending on the query region, it may describe a point, # a box, a pair of (geodetically adjacent) boxes, a vertical line # segment, a horizontal line segment, a pair of collinear # (geodetically adjacent) horizontal line segments, or a polygon. # # The discontinuity at the +/-180 meridian is handled correctly, # but the discontinuities at the poles are not. # # Exceptions thrown: # # none # # AUTHOR # # Greg Janee # gjanee@alexandria.ucsb.edu # # HISTORY # # $Log: Spatial_InformixMapInfo.py,v $ # Revision 1.1 2002/10/22 02:58:09 gjanee # Initial revision # import types import edu.ucsb.adl.middleware M = edu.ucsb.adl.middleware import UniversalTranslator UT = UniversalTranslator _operatorMapping = { "contains" : "ST_Contains", "is-contained-in" : "ST_Within", "overlaps" : "ST_Overlaps" } class Spatial_InformixMapInfo (UT.Paradigm): def __init__ (self, table, idColumn, footprintColumn, cardinality): UT.assertType(table, types.StringType) UT.assertType(idColumn, types.StringType) UT.assertType(footprintColumn, types.StringType) UT.assertType(cardinality, UT.Cardinality) self.table = table self.idColumn = idColumn self.footprintColumn = footprintColumn self.cardinality = cardinality def translateBucketAtomic (self, constraint, vocabularies): UT.assertType(constraint, M.Query.SpatialConstraint) assert constraint.getOperator() in UT.standardSpatialOperators,\ "unsupported operator: " + constraint.getOperator() if constraint.getType() == M.Query.SpatialConstraint.BOX: north = constraint.getNorthBoundary() south = constraint.getSouthBoundary() east = constraint.getEastBoundary() west = constraint.getWestBoundary() if west < east: if north == south: target = "ST_Polyline(LIST{ST_Point(" + str(west) +\ ", " + str(north) + "), ST_Point(" + str(east) +\ ", " + str(north) + ")})" else: target = "HG_Box(" + str(west) + ", " + str(south) +\ ", " + str(east) + ", " + str(north) + ")" elif west == east: if north == south: target = "ST_Point(" + str(west) + ", " + str(north) + ")" else: target = "ST_Polyline(LIST{ST_Point(" + str(west) +\ ", " + str(north) + "), ST_Point(" + str(west) +\ ", " + str(south) + ")})" else: if north == south: target = "ST_Spatial(LIST{ST_Polyline(LIST{ST_Point(" +\ str(west) + ", " + str(north) +\ "), ST_Point(180.0, " + str(north) +\ ")}), ST_Polyline(LIST{ST_Point(-180.0, " +\ str(north) + "), ST_Point(" + str(east) + ", " +\ str(north) + ")})})" else: target = "ST_Spatial(LIST{HG_Box(" + str(west) + ", " +\ str(south) + ", 180.0, " + str(north) +\ "), HG_Box(-180.0, " + str(south) + ", " + str(east) +\ ", " + str(north) + ")})" else: target = "" for vertex in constraint.getVertices(): v = "ST_Point(" + str(vertex.longitude) + ", " +\ str(vertex.latitude) + ")" if target == "": firstVertex = v target = target + v + ", " target = "ST_Polygon(ST_Polyline(LIST{" + target + firstVertex +\ "}))" table = UT.TableRef(self.table) return UT.Select( [UT.MainFrom(table, self.idColumn, self.cardinality)], UT.Expression([_operatorMapping[constraint.getOperator()] + "(", table, "." + self.footprintColumn + ", '" + target + "')"]))