Create geometries

There are several methods for creating geometries in a database:

  • Load from Well Known Text (WKB) 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 Load spatial data from a Well Known Text (WKT) file.

  • Load from ESRI shapefiles   You can load data in ESRI shapefile format. Following this method, you use the sa_describe_shapefile system procedure to determine the columns and spatial data types contained in the shapefile. Then, you can use the LOAD TABLE statement See Tutorial: Experimenting with the spatial features.

  • Use a SELECT...FROM OPENSTRING statement   You can execute a SELECT...OPENSTRING FORMAT SHAPEFILE 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.