Create geometries

There are several methods for creating geometries in a database:

  • Load from Well Known Text (WKT) or Well Known Binary (WKB) formats   You can load or insert data in WKT or WKB formats. These formats are defined by the OGC, and all spatial database vendors support them. SQL Anywhere performs automatic conversion from these formats to geometry types. For an example of loading from WKT, see Loading spatial data from a Well Known Text (WKT) file.

  • Load from ESRI shapefiles   You can load data from ESRI shapefiles into a new or existing table. There are a number of ways to do this. See Support for ESRI shapefiles and Lesson 3: Load the ESRI shapefile data.

  • Use a SELECT...FROM OPENSTRING statement   You can execute a SELECT... FROM OPENSTRING statement on a file containing the spatial data. For example:
    INSERT INTO world_cities( country, city, point )
       SELECT country, city, NEW ST_Point( longitude, latitude, 4326 )
          FROM OPENSTRING( FILE 'capitalcities.csv' ) 
               WITH( 
                     country   CHAR(100),
                     city      CHAR(100),
                     latitude  DOUBLE,
                     longitude DOUBLE )
    

    See Openstring expressions in a FROM clause.

  • Create coordinate points by combining latitude and longitude values   You can combine latitude and longitude data to create a coordinate of spatial data type ST_Point. For example, if you had a table that already has latitude and longitude columns, you can create an ST_Point column that holds the values as a point using a statement similar to the following:
    ALTER TABLE my_table 
       ADD point AS ST_Point(SRID=4326) 
       COMPUTE( NEW ST_Point( longitude, latitude, 4326 ) );

  • Create geometries using constructors and static methods   You can create geometries using constructors and static methods. See Instantiating instances of a UDT and Using static methods.