Author: Xian
Table of contents
1. Background
SuperMap iObjects Java
It is a component-based GIS development platform for GIS application system developers. It has powerful geographic data management, editing, display, analysis and other functions, and it has strong ease of use and rich help resources, suitable for rapid development of large-scale GIS application systems.
This article mainly introduces how to use SuperMap iObjects Java
components as the functional basis and combine the SpringBoot open source framework to quickly build GIS background services.
2. Environment preparation
2.1. System environment
operating system | support | illustrate |
---|---|---|
Windows | ✔ | Windows platform recommended hardware configuration requirements: Processor: above 2.00 GHz Memory requirements: 2 GB Hard disk capacity: 100 GB |
Linux | ✔ | Minimum hardware requirements for Linux platform: CPU: 1.00 GHz (x86 architecture) Memory: 512 MB Hard disk space: 40 GB |
2.2. Development environment
software | Version | download link | illustrate |
---|---|---|---|
iObjects Java | 10i and above | iObjects Java download link | SuperMap officially provides the iObjects Java component Maven warehouse , which can be used directly |
IDEA | 2020.3.4 and above | IDEA download address | |
SpringBoot | 2.7.x | * | IDEA can directly select the required version when creating a new SpringBoot project |
Swagger | 3.0.0 | * | Configured in the pom.xml file of the SpringBoot project |
3. Technology stack
3.1. SuperMap iObjects Java
SuperMap iObjects Java components provide professional GIS functions for background services.
3.2. SpringBoot
SpringBoot is a framework for developers to quickly develop Java background services.
3.3. Swagger
Swagger is a RESTFUL interface document online automatic generation + functional testing function software. After SpringBoot integrates Swagger, it can be used by developers and service users to learn and test service interfaces.
4. Create a new SpringBoot project
-
IDEA creates a new SpringBoot project
-
Configure Maven and project Java version
-
Configure SpringBoot dependent modules
5. Configure the Swagger module
springfox-boot-starter is a SpringBoot library that provides Spring applications with the ability to quickly and easily create Swagger documentation. Swagger documentation can help developers better understand and use RESTful APIs.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
-
Modify the application.properties file configuration
Since the default path matching strategy of the SpringBoot 2.7.x version is that
path-pattern-matcher
after the current SpringBoot project integrates Swagger 3.0.0, if the service program is run directly, the exception of "Failed to start bean 'documentationPluginsBootstrapper'; nested exception..." will be thrown , so the following configuration needs to be added to the application.properties file to modify the path matching strategy:spring.mvc.pathmatch.matching-strategy=ant_path_matcher
6. Configure SuperMap iObjects Java components
SuperMap officially provides the supermap-maven warehouse (https://maven.supermap.io) , which contains SuperMap iServer, SuperMap iObjects and other related Jars and dependent third-party libraries. By adding the official SuperMap library in the pom file, users can directly add the libraries used in development and their dependencies to the maven project, which is convenient for users to solve problems such as missing dependencies when using the official SuperMap library.
-
Add SuperMap Maven remote warehouse
Add the SuperMap Maven repository node in the pom.xml of the SpringBoot project.
<repositories> <repository> <id>supermap</id> <url>https://maven.supermap.io/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories>
-
Add SuperMap iObjects Java dependency
Add component dependencies in the pom.xml of the SpringBoot project
SuperMap iObjects Java
, and add com.supermap.data dependencies as follows.<dependency> <groupId>com.supermap</groupId> <artifactId>com.supermap.data</artifactId> <version>11.0.1-21501-98146</version> </dependency>
-
Configure iObjects Java component environment variables
Since
SuperMap iObjects Java
the core GIS function of the component is implemented based on C++, and then invoked through JNI, only adding the dependent iObjects Java component jar package through Maven will cause the lack of C++ dependent libraries. Therefore, it is necessary to configure the dependent environment of the iObjects Java component on the development environment machine.operating system Configure environment variables Windows Add the SuperMap iObjects Java installation directory\Bin path to the system environment variable PATH Linux export LD_LIBRARY_PATH=SuperMap iObjects Java installation directory\Bin export PATH=$LD_LIBRARY_PATH:$PATH
7. Realization of GIS functions
In the SpringBoot project where iObjects Java component dependencies have been added, the GIS business functions required by the project can be directly implemented in the SpringBoot framework based on the GIS core functions provided by the iObjects Java component. The following takes a simple data service implementation code as an example.
-
Create a new data service controller (DataServiceController)
@Api(tags = "数据服务") @RestController @RequestMapping("/data") public class DataServiceController { }
-
open workspace
@Operation(summary = "打开工作空间", description = "打开文件型工作空间") @ApiImplicitParams({ @ApiImplicitParam(name = "workspacePath", value = "文件型工作空间路径", dataType = "String", dataTypeClass = String.class) }) @GetMapping("/openWorkspace") public boolean openWorkspace(String workspacePath) { if (workspace != null) { workspace.close(); workspace.dispose(); workspace = null; } File file = new File(workspacePath); String workspaceName = file.getName(); String[] splitted = workspaceName.split("\\."); workspaceName = ""; for (int i = 0; i < splitted.length - 1; i++) { workspaceName = workspaceName.concat(splitted[i]); if (i < splitted.length - 2) { workspaceName = workspaceName.concat("."); } } WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo(workspacePath); workspaceConnectionInfo.setName(workspaceName); workspace = new Workspace(); return workspace.open(workspaceConnectionInfo); }
-
Get a list of data source names
@Operation(summary = "获取数据源列表", description = "获取当前工作空间内的数据源列表") @GetMapping("/getDatasourceNames") public ArrayList<String> getDatasourceNames() { ArrayList<String> datasourceNames = new ArrayList<>(); if (workspace != null) { Datasources datasources = workspace.getDatasources(); for (int i = 0; i < datasources.getCount(); i++) { Datasource datasource = datasources.get(i); String datasourceAlias = datasource.getAlias(); datasourceNames.add(datasourceAlias); } } return datasourceNames; }
-
Get a list of dataset names
@Operation(summary = "获取数据集名称列表", description = "根据输入的数据源名称获取数据集名称列表") @ApiImplicitParams({ @ApiImplicitParam(name = "datasourceName", value = "数据源名称", dataType = "String", dataTypeClass = String.class) }) @GetMapping("/getDatasetNames") public ArrayList<String> getDatasetNames(String datasourceName) { ArrayList<String> datasetNames = new ArrayList<>(); if (workspace != null) { Datasources datasources = workspace.getDatasources(); if (datasources.contains(datasourceName)) { Datasource datasource = datasources.get(datasourceName); Datasets datasets = datasource.getDatasets(); for (int i = 0; i < datasets.getCount(); i++) { Dataset dataset = datasets.get(i); datasetNames.add(dataset.getName()); } } } return datasetNames; }
-
Get the specified dataset records
@Operation(summary = "获取指定数据集记录", description = "根据输入的数据源名称、数据集名称获取记录") @ApiImplicitParams({ @ApiImplicitParam(name = "datasourceName", value = "数据源名称", dataType = "String", dataTypeClass = String.class), @ApiImplicitParam(name = "datasetName", value = "数据集名称", dataType = "String", dataTypeClass = String.class) }) @GetMapping("/getRecordset") public JSONArray getRecordset(String datasourceName, String datasetName) { JSONArray jsonArray = new JSONArray(); if (workspace != null) { Datasources datasources = workspace.getDatasources(); if (datasources.contains(datasourceName)) { Datasource datasource = datasources.get(datasourceName); Datasets datasets = datasource.getDatasets(); if (datasets.contains(datasetName)) { Dataset dataset = datasets.get(datasetName); if (dataset instanceof DatasetVector) { DatasetVector datasetVector = (DatasetVector) dataset; Recordset recordset = datasetVector.getRecordset(false, CursorType.STATIC); FieldInfos fieldInfos = recordset.getFieldInfos(); for (int i = 0; i < recordset.getRecordCount(); i++) { recordset.moveTo(i); JSONObject subJsonObject = new JSONObject(); for (int j = 0; j < fieldInfos.getCount(); j++) { FieldInfo fieldInfo = fieldInfos.get(j); String fieldName = fieldInfo.getName(); Object fieldValue = recordset.getFieldValue(fieldName); if (fieldInfo.isSystemField() && fieldInfo.getType() == FieldType.LONGBINARY) { fieldValue = Toolkit.GeometryToGeoJson(recordset.getGeometry()); } subJsonObject.put(fieldName, fieldValue); } jsonArray.add(subJsonObject); } recordset.close(); recordset.dispose(); } } } } return jsonArray; }
8. Summary
After developing according to the above tutorial, the GIS service shown in the figure below can be realized.
In addition, this tutorial also provides the sample code of GIS background service developed according to the above tutorial , or you can directly download the sample code and compile it through Maven to run and debug it.