SQL Anywhere Spatial Data Company
Total Page:16
File Type:pdf, Size:1020Kb
PUBLIC SQL Anywhere Server Document Version: 17 – 2020-12-11 SQL Anywhere Spatial Data company. All rights reserved. All rights company. affiliate THE BEST RUN 2020 SAP SE or an SAP SE or an SAP SAP 2020 © Content 1 SQL Anywhere Server - Spatial Data Support.......................................4 1.1 Spatial Data.................................................................4 Spatial Reference Systems (SRS) and Spatial Reference Identifiers (SRID)..................7 Units of Measure...........................................................9 Support for Spatial Data.....................................................11 Recommended Reading on Spatial Topics........................................ 22 Creating a Spatial Column (SQL Central).........................................22 Creating a Spatial Column (SQL)...............................................25 Indexes on Spatial Columns..................................................26 Spatial Data Type Syntax.................................................... 27 How to Create Geometries................................................... 31 Viewing Spatial Data as Images (Interactive SQL)...................................32 Viewing Spatial Data as Images (Spatial Viewer)....................................34 Loading Spatial Data from a Well Known Text (WKT) File..............................36 Creating a Unit of Measure...................................................40 Creating a Spatial Reference System............................................41 Advanced Spatial Topics.....................................................43 Tutorial: Experimenting with the Spatial Features...................................56 1.2 Spatial Types and Functions.....................................................70 ST_CircularString Type......................................................71 ST_CompoundCurve Type................................................... 81 ST_Curve Type........................................................... 88 ST_CurvePolygon Type......................................................97 ST_GeomCollection Type....................................................112 ST_Geometry Type........................................................122 ST_LineString Type.......................................................308 ST_MultiCurve Type.......................................................318 ST_MultiLineString Type....................................................329 ST_MultiPoint Type....................................................... 336 ST_MultiPolygon Type..................................................... 343 ST_MultiSurface Type..................................................... 352 ST_Point Type...........................................................366 ST_Polygon Type.........................................................391 ST_SpatialRefSys Type.....................................................404 ST_Surface Type......................................................... 415 Spatial Compatibility Functions...............................................422 SQL Anywhere Spatial Data 2 PUBLIC Content List of All Supported Methods................................................470 List of All Supported Constructors.............................................481 List of Static Methods..................................................... 482 List of Aggregate Methods..................................................485 List of Set Operation Methods................................................486 List of Spatial Predicates................................................... 487 SQL Anywhere Spatial Data Content PUBLIC 3 1 SQL Anywhere Server - Spatial Data Support This book describes the SQL Anywhere spatial data support and how the spatial features can be used to generate and analyze spatial data. The following image represents the distributions of cities and towns across the United States and is one example of the interesting operations you can perform on spatial data. In this section: Spatial Data [page 4] Spatial data is data that describes the position, shape, and orientation of objects in a defined space. Spatial Types and Functions [page 70] The spatial data types can be considered like data types or classes. Each spatial data type has associated methods and constructors you use to access the data. 1.1 Spatial Data Spatial data is data that describes the position, shape, and orientation of objects in a defined space. Spatial data is represented as 2D geometries in the form of points, curves (line strings and strings of circular arcs), and polygons. For example, the following image shows the state of Massachusetts, representing the union of polygons representing ZIP code regions. SQL Anywhere Spatial Data 4 PUBLIC SQL Anywhere Server - Spatial Data Support Two common operations performed on spatial data are calculating the distance between geometries, and determining the union or intersection of multiple objects. These calculations are performed using predicates such as intersects, contains, and crosses. The spatial data documentation assumes you already have some familiarity with spatial reference systems and with the spatial data you intend to work with. Note Spatial data support for 32-bit Windows and 32-bit Linux requires a CPU that supports SSE2 instructions. This support is available with Intel Pentium 4 or later (released in 2001) and AMD Opteron or later (released in 2003). The software provides storage and data management features for spatial data, allowing you to store information such as geographic locations, routing information, and shape data. These information pieces are stored as points and various forms of polygons and lines in columns defined with a corresponding spatial data type (such as ST_Point and ST_Polygon). You use methods and constructors to access and manipulate the spatial data. The software also provides a set of SQL spatial functions designed for compatibility with other products. Example Spatial data support lets application developers associate spatial information with their data. For example, a table representing companies could store the location of the company as a point, or store the delivery area for the company as a polygon. This could be represented in SQL as: CREATE TABLE Locations( ID INT, ManagerName CHAR(16), StoreName CHAR(16), Address ST_Point, DeliveryArea ST_Polygon ) SQL Anywhere Spatial Data SQL Anywhere Server - Spatial Data Support PUBLIC 5 The spatial data type ST_Point in the example represents a single point, and ST_Polygon represents an arbitrary polygon. With this schema, the application could show all company locations on a map, or find out if a company delivers to a particular address using a query similar to the following: CREATE VARIABLE @pt ST_Point; SET @pt = ST_Geometry::ST_GeomFromText( 'POINT(1 1)' ); SELECT * FROM Locations WHERE DeliveryArea.ST_Contains( @pt ) = 1 In this section: Spatial Reference Systems (SRS) and Spatial Reference Identifiers (SRID) [page 7] In the context of spatial databases, the defined space in which geometries are described is called a spatial reference system (SRS). Units of Measure [page 9] Geographic features can be measured in degrees of latitude, radians, or other angular units of measure. Support for Spatial Data [page 11] There are several spatial data types supported by the software. Recommended Reading on Spatial Topics [page 22] Consider the following resources for learning about spatial data. Creating a Spatial Column (SQL Central) [page 22] Add spatial data to any table by adding a column that supports spatial data. Creating a Spatial Column (SQL) [page 25] Add spatial data to any table by adding a column that supports spatial data. Indexes on Spatial Columns [page 26] When you create spatial index, do not include more than one spatial column in the index, and position the spatial column last in the index definition. Spatial Data Type Syntax [page 27] The SQL/MM standard defines spatial data support in terms of user-defined extended types (UDTs) built on the ANSI/SQL CREATE TYPE statement. How to Create Geometries [page 31] There are several methods for creating geometries in a database. Viewing Spatial Data as Images (Interactive SQL) [page 32] View a geometry as an image using the Spatial Preview tab to understand what the data in the database represents. Viewing Spatial Data as Images (Spatial Viewer) [page 34] View multiple geometries as an image to understand what the data in the database represents using the Spatial Viewer. Loading Spatial Data from a Well Known Text (WKT) File [page 36] Add spatial data to a table by using a Well Known Text file (WKT) that contains text that can be used to load spatial data into a database and be represented as geometry. Creating a Unit of Measure [page 40] Create a unit of measure that is appropriate for your data. Creating a Spatial Reference System [page 41] SQL Anywhere Spatial Data 6 PUBLIC SQL Anywhere Server - Spatial Data Support Create a spatial reference system (SRS) that uses an existing one as a template on which to base your settings using the Create Spatial Reference System Wizard. Advanced Spatial Topics [page 43] Several topics are provided for a more in-depth understanding of spatial data. Tutorial: Experimenting with the Spatial Features [page 56] This tutorial allows you to experiment with the spatial features. Related Information Supported Spatial Data Types and Their Hierarchy [page 11] Spatial Compatibility Functions [page 422] 1.1.1 Spatial Reference Systems