com.supermap.data

Class DatasetVector



  • public class DatasetVector
    extends Dataset

    The DatasetVector class.

    This DatasetVector object is mainly to describe and manage the vector dataset. The operations on the vector dataset include data querying, data modifying, data deleting, building index and etc.

    You need to open the dataset before performing any operations on the dataset-- Dataset.open() Method

    • Method Detail

      • getFieldCount

        public int getFieldCount()
        Gets the number of the fields in the vector dataset.

        This method is safe, with the thread safety level being level2.

        Returns:
        the number of the fields in the vector dataset.
      • getFieldInfos

        public FieldInfos getFieldInfos()
        Gets the FieldInfos object, that is, all fields information in attribute table.

        This method is safe, with the thread safety level being level2.For a detailed description of thread safety, refer to the “Multithreaded Technical Documentation"

        Returns:
        the FieldInfos object
      • getRecordset

        public Recordset getRecordset(boolean isEmptyRecordset,
                                      CursorType cursorType)
        Returns the Recordset which contains all the records or a empty recordset with the specified parameter.
        Parameters:
        isEmptyRecordset - This parameter indicates that whether to return a empty recordset.
        cursorType - the specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType. CursorType .
        Returns:
        isEmptyRecordset return empty recordset if the parameter is true; return the recordset that contains all the records it the parameter is false.
      • query

        public Recordset query(QueryParameter queryParameter)
        Queries records through setting query parameters. The method will query spatial information and attribute information.

        This method is safe, with the thread safety level being level2.For a detailed description of thread safety, refer to the “Multithreaded Technical Documentation"

        Parameters:
        queryParameter - Defined query conditions.
        Returns:
        the recordset contains the query results.
      • append

        public boolean append(Recordset recordset)
        Adds the Recordset to the DatasetVector. Appending the field directly when the field name in the recordset and the vector dataset is same; otherwise ignoring the appending operation. <,p>After appending, the recordset will positioned after the last record in the recordset, that is, the IsEOF attribute is true.
        Parameters:
        recordset - the recordset object added.
        Returns:
        true if successful; otherwise, false.
        Example:
        The following example demonstrates how to add the recordset to the vector dataset.
         public void appendTest() {
                // Imagines that you open a workspace object, and there is a database datasource object in the workspace
                // The datasource includes two vector dataset: World, Ocean.
                DatasetVector datasetVector = (DatasetVector) datasource.getDatasets().
                                              get("World");
                DatasetVector datasetVector1 = (DatasetVector) datasource.getDatasets().
                                               get("Ocean");
        
                // Returns all records of the dataset named "Ocean" and appends it the dateset named "World"
                Recordset recordset = datasetVector1.getRecordset(false,
                        CursorType.DYNAMIC);
                if (datasetVector.append(recordset)) {
                    System.out.println("Succeed to append dataset");
                }
        
                // Releases resources
                recordset.dispose();
                datasetVector.close();
                datasetVector1.close();
            }
         
      • append

        public boolean append(Recordset recordset,
                              java.lang.String tileName)
        Appends the Recordset to the DatasetVector according to sheet name. It is required that the index of the vector dataset is tile index. The newly added records will be regarded as a tile of the tile index. While appending, shared fields will be appended to the vector dataset directly and fields that are not common to the recordset and the vector dataset will be ignored. <,p>After appending, the recordset will positioned after the last record in the recordset, that is, the IsEOF attribute is true.

        Currently, only the ORACLEPLUS engine of EngineType supports for adding data in sheet for vector datasets.

        Parameters:
        recordset - the recordset object added.
        tileName - the added sheet name.
        Returns:
        true if successful; otherwise, false.
      • deleteRecords

        public boolean deleteRecords(int[] id)
        Deletes the records in the vector dataset through the array of ID.
        Parameters:
        id - the array of ID to be deleted.
        Returns:
        Returns true if it is removed successfully; false otherwise.
      • query

        public Recordset query(int[] ids,
                               CursorType cursorType)
        Query by ID.
        Parameters:
        ids - ID array
        cursorType - The specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType .
        Returns:
        the recordset contains the query results.
      • query

        public Recordset query(Rectangle2D bounds,
                               java.lang.String attributeFilter,
                               CursorType cursorType)
        Used to query the records that falls in certain extent and meet the conditions.
        Parameters:
        bounds - the given bounds.
        attributeFilter - Query filter. It is equal to Where in SOL expression.
        cursorType - The specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType .
        Returns:
        the recordset contains the query results.
      • query

        public Recordset query(Rectangle2D bounds,
                               CursorType cursorType)
        Query records which locate in the given space bounds.
        Parameters:
        bounds - the given bounds.
        cursorType - The specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType .
        Returns:
        the recordset contains the query results.
      • query

        public Recordset query(java.lang.String attributeFilter,
                               CursorType cursorType)
        Queries vector dataset with the query filter.This method is used to query the spatial data and the attribute data.

        For UDB, when the parameters of time is passed, it's required that the text should be written as follows. For example, "2008-5-12 14:28:00" should be written "to_date(2008-5-12 14:28:00)" Note that quotation marks is not required in the brackets.

        Parameters:
        attributeFilter - query filter. It is equal to Where in SOL expression.
        cursorType - The specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType .
        Returns:
        The recordset contains the query results.
        Example:
        The following codes demonstrates how to construct query clause with the string date field.
         public void queryTest(){
               SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
               //Constructs a time object
               Date dateOld=new Date(2010,1,10,11,12,13);
               //Constructs an object of current time 
               Date dateNow = new Date();
               //Formatted into a string
               String dtStrOld = format.format(dateOld);
               String dtStrNow = format.format(dateNow);
               //Constructs query conditions with two time strings
               String filter = "TimeField between to_date(" + dtStrOld + ") and to_date(" + dtStrNow + ")";
               //Passes the conditions to the method Query() to query the recordset.
               Recordset recordset = vector.Query(filter,CursorType.Static);
               }
         
      • query

        public Recordset query(Geometry geometry,
                               double bufferDistance,
                               CursorType cursorType)
        Queries the records in the buffer zone of the specified Geometry object.
        Parameters:
        geometry - The Geometry object used for querying.
        bufferDistance - The radius of the buffer.
        cursorType - The specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType .
        Returns:
        the recordset contains the query results.
      • query

        public Recordset query(Geometry geometry,
                               double bufferDistance,
                               java.lang.String attributeFilter,
                               CursorType cursorType)
        Query records which locate in the buffer zone of the specified Geometry object and satisfy certain condition at the same time.
        Parameters:
        geometry - The Geometry object used for querying.
        bufferDistance - The radius of the buffer.
        attributeFilter - Query condition, usually a SQL statement
        cursorType - The specified cursor type of the query result.DYNAMIC and STATIC are supported cursor types. DYNAMIC indicates the recordset can be modified, and STATIC indicates the recordset is read-only. For more information, please refer to the CursorType .
        Returns:
        the recordset contains the query results.
      • getChildDataset

        public DatasetVector getChildDataset()
        Gets the child dataset of the vector dataset. It is mainly used in the network dataset.
        Returns:
        The child dataset.
      • fromGeoJSON

        public boolean fromGeoJSON(java.lang.String geoJSON)
        Gets the geometry object from the GeoJSON string, and store it to the dataset

        Only support point, line, region and CAD datasets. Get the point, line and region objects

        Parameters:
        geoJSON - The GeoJSON string
        Returns:
        true if successful; otherwise, false.
      • toGeoJSON

        public java.lang.String toGeoJSON(boolean hasAttributte,
                                          int startID,
                                          int endID)
        Convert the objects with specified start and end SmID to GeoJSON string.

        Only support point, line, region and CAD datasets. Convert the point, line and region objects. When hasAtrributte is true, the result includes the attribute value; when hasAtrribute is false, it only includes the geometry object.

        Parameters:
        hasAttributte - Whether it contains attribute values
        startID - the start SmID
        endID - the end SmID
        Returns:
        Returns the obtained GeoJSON string. It will return null if no result;
      • queryByKeyword

        public void queryByKeyword(java.lang.String fieldName,
                                   java.lang.String keywords,
                                   Geometry geoRegion,
                                   int count)
        Attributes query. Query the record that contains the keyword in the specified field; The way to get the results:setQueryListener(QueryListener listener)
        Parameters:
        fieldName - Query field name, such as Name, Name_PY, Name_PYSZM, that is, the name of the field, the name of the alphabet field, the name of the first letter of the alphabet field
        keywords - Query the keyword for the field
        geoRegion - It can specify the range. if it is NULL, it means query in full range
        count - The returned query result count. Default is 10.More than 100 by 100 count.
      • queryByFilter

        public void queryByFilter(java.lang.String attributeFilter,
                                  Geometry geoRegion,
                                  int count)
        Spatial query, query the recordset which meets the field condition within specified spatial range The way to get the results:setQueryListener(QueryListener listener)
        Parameters:
        attributeFilter - The query conditions, such as Kind=2008
        geoRegion - The query region
        count - The returned query result count. Default is 10.More than 100 by 100 count.
      • fromGeoJSON

        public int fromGeoJSON(java.io.File file)
        Read the GeoJSON data in dataset from the specified file (txt) and import to the current dataset. When importing, if the record SmID exists, then modify this record, or add the record. The supported dataset type: point datasets, line datasets, region datasets and CAD datasets. Geometry types: point, line and region (GeoPoint, GeoLine, GeoRegion). Notes: this method is used with toGeoJSON(File). The reading file is also set by the toGeoJSON(File). If the format in the used file is different from the exported file toGeoJSON(File), it maybe fail.
        Parameters:
        file - Stores the GeoJSON data in dataset. It is usually the txt file
        Returns:
        count The imported record count successfully
      • toGeoJSON

        public int toGeoJSON(java.io.File file)
        Convert all the records in the current recordset to the GeoJSON string, and store in the specified file (txt). Each line is a record with the end tag "\n". The supported dataset type: point datasets, line datasets, region datasets and CAD datasets. Geometry types: point, line and region (GeoPoint, GeoLine, GeoRegion).
        Parameters:
        file - Used to store the GeoJSON string file. If the file exist, it can append to the last; otherwise, it will create a new file.
        Returns:
        count The imported record count successfully
      • convertToLine

        public GeoLine convertToLine()
        Convert all points in the point dataset to the line object. It only supports the point dataset

        If it is not the point dataset, it will throw an exception. If it is less than two points in the dataset, return null

        Returns:
        GeoLine Converted successfully. Return the line object after converted; otherwise, return null
      • convertToLine

        public GeoLine convertToLine(java.lang.String fieldName,
                                     java.lang.String fieldValue)
        Convert all points that have the same fields in the point dataset to the line objects. It only supports the point dataset

        If it is not the point dataset, it will throw an exception. if there is no specified field or the point containing the field in the point dataset, and the results are less than two points, return null

        Parameters:
        fieldName - Field Name
        fieldValue - Field Value
        Returns:
        GeoLine Converted successfully. Return the line object after converted; otherwise, return null
      • getSpatialIndexType

        public SpatialIndexType getSpatialIndexType()
        Returns the current spatial index type
        Returns:
        the current spatial index type
      • isSpatialIndexDirty

        public boolean isSpatialIndexDirty()
        Returns whether the spatial index of the vector dataset needs to be rebuilt. Because after modifying the data process, you may need to rebuild the spatial index. note: When the vector dataset has no spatial index, it returns true if the number of records has reached the requirement to create a spatial index. It is recommended that the user create a spatial index; otherwise, false. Returns true if the vector dataset already has a spatial index (except the Gallery index), but its number of records has been unable to meet the requirements for creating a spatial index.
        Returns:
        True, if the index creates successfully; otherwise false.
      • isSpatialIndexTypeSupported

        public boolean isSpatialIndexTypeSupported(SpatialIndexType spatialIndexType)
        Determines whether the current dataset supports the spatial index of the specified type
        Parameters:
        spatialIndexType - Specifies the type of spatial index
        Returns:
        If the specified spatial index type is supported, the return value is true, otherwise false
      • buildSpatialIndex

        public boolean buildSpatialIndex(SpatialIndexInfo spatialIndexInfo)

        Creates a spatial index for the vector dataset based on the specified spatial index information.

        Note:

        1. The point dataset in the database does not support the quadtree (QTree) index and the R tree index (RTree);
        2. The network dataset does not support any type of spatial index;
        3. Attribute data sets do not support any type of spatial index;
        4. Routing data set does not support page index (TILE)
        5. Composite data sets do not support multi-level grid index;
        6. Database index to more than 1000 can be created when the index.
        Parameters:
        spatialIndexInfo - Specifies the spatial index information object
        Returns:
        True, if the index creates successfully; otherwise false.
      • buildSpatialIndex

        public boolean buildSpatialIndex(SpatialIndexType spatialIndexType)

        Creates a spatial index for a vector dataset based on the given spatial index type. For space index types see Spatialindextype enumeration type descriptions.

        Notes:

        1. The point dataset in the database does not support the quadtree (QTree) index and the R tree index (RTree);
        2. The network dataset does not support any type of spatial index;
        3. Attribute data sets do not support any type of spatial index;
        4. Routing data set does not support page index (TILE)
        5. Composite data sets do not support multi-level grid index;
        6. Database index to more than 1000 can be created when the index.
        7. This operation needs to occur when the dataset is closed, and rebuilding the spatial index fails if the current dataset is still open.
        Parameters:
        spatialIndexType - Specifies the type of space index to create.
        Returns:
        True, if the index creates successfully; otherwise false.
        Example:
        The following code demonstrates whether a data set's spatial index needs to be rebuilt, if it needs to be rebuilt, a R-tree index is established, and if no rebuild is required, the existing dataset is judged to support the multilevel grid index.
          
             public void buildPyramidTest() { 
                 //Suppose you open a Workspace workspace object, there is a data source DataSource object in the workspace 
                 // Remove the vector dataset named "World" from the datasource (datasetvector)
                 // The following code demonstrates whether a data set's spatial index needs to be rebuilt, if it needs to be rebuilt, a R-tree index is established, and if no rebuild is required, the existing dataset is judged to support the multilevel grid index.
                 DatasetVector datasetVector = (DatasetVector)
                 datasource.getDatasets(). get("World"); 
                 if (datasetVector.isSpatialIndexDirty()) { 
                     //Delete an existing index
                     datasetVector.dropSpatialIndex(); 
                     //Close dataset
                     datasetVector.close();
         
                     //Rebuilding the R-tree index 
                     if(datasetVector.buildSpatialIndex(SpatialIndexType.RTREE)) {
                         SpatialIndexType spatialindextype = datasetVector.
                         getSpatialIndexType(); 
                         ystem.out.println("The new space index is of type:" + spatialindextype); 
                     } 
                 } else { 
                     //If you do not need to rebuild, determine whether the existing data set supports multi-level grid index 
                     if(datasetVector.isSpatialIndexTypeSupported(SpatialIndexType.MULTI_LEVEL_GRID)) { 
                         System.out.printl("This dataset supports multilevel grid indexingn"); 
                     } else {
                         System.out.printl("The dataset does not support multilevel grid indexes"); 
                     } 
                 } 
             }
             
      • reBuildSpatialIndex

        public boolean reBuildSpatialIndex()
        In the original spatial index based on the reconstruction, if the original spatial index is destroyed, then the reconstruction can continue to use after the success.
        Returns:
        True, if the index creates successfully; otherwise false.
      • dropSpatialIndex

        public boolean dropSpatialIndex()
        Delete spatial index
        Returns:
        Returns true if it is removed successfully; false otherwise.
      • computeBounds

        public Rectangle2D computeBounds()
        Calculate the spatial extent of the dataset
        Returns:
        the spatial extent of the dataset
      • getCharset

        public Charset getCharset()
        Gets the character set of the vector dataset
        Returns:
        dataset