Use Openlayer to use GeoServer to edit features to PostGIS attention issues (WFS-T)

Source: Internet
Author: User
Tags postgis

Openlayer+geoserver+postgis is the most common open source GIS solution, and editing features is one of the most common operations in GIS. This paper explains the problems of using Openlayer to make use of geoserver editing features to PostGIS.


One, the spatial database PostGIS attention problem

1. The data table to be edited in PostGIS should have edit permissions, such as INSERT, Update, Delete, and the setting method is shown in the following figure. Assign permissions to the appropriate users by adding/modifying users/groups.



2. Types of Geometry fields (Geom/geometry) in the datasheet (point/multipoint, linestring/multilinestring, Polygon/multipolygon ) should be consistent with the geometry type of the edited feature in Openlayer, not one for point and one for multipoint. This should be determined when the table or Shapefile file is created (details can be found in the two methods of Shapefile import PostGIS and compared), or the geometry type of the feature is set in Openlayer.

3. For the wfs-t operation of the data table, must have a primary key (primary key), otherwise there will be read-only error prompts.


Second, GIS server GeoServer attention issues

1. Because WFS-T operations involve things, the WFS service should be at the Transaction/completelevel, as shown in the following figure:



2. If the user name and password (username/password) for the connection GeoServer is not set in the Ajax request, it should be set in Security→data and the role_anonymous Add to the selected role, as shown in the following illustration. However, this setup has drawbacks, and once other users know the address of the WFS in GeoServer, they can modify the data arbitrarily.



3. In settings → Global , set up the details of WFS execution in developer mode (Developer), log to see the detailed process of WFS execution, and quickly locate the problem and resolve problems, as shown in the following figure. Log file under the Logs folder of the Data_dir path, record your profile to select geotools_developer_logging.properties or verbose_ Logging.properties, the latter records more detailed information, other differences are unclear.



third, the front-end openlayers attention problems

1. If the Web server and the GIS server are not in the same domain, there will be cross-domain access issues, the workaround is described in the blog openlayers WFS cross-domain problem solving approach.

2. The geometry type of the feature being edited in the code, especially the geometry type of the new feature (as reflected in the type setting of the draw space ), must be consistent with several types of data tables in PostGIS, as in Point/linestring/polygon, Cannot be one point and the other is multipoint.

3. For data security, when role_anonymous is not added to Selected Roles , the user name and password of the connection GeoServer server must be set in the AJAX request (username/ Password).

4. PostGIS The Geometry field name of the datasheet in the default is geom,openlayers the Geometry field name of the feature is geometry, and the feature to be in the library must have a GEOM field, otherwise the geometry field is empty after the entry, and the following settings can be made. If you set the Geometry field name to geometry when you created the datasheet, you do not have to set it.

Feature.set (' Geom ', Feature.getgeometry ());

5. The measured results show that the primary key (ID) in PostGIS is automatically generated and does not work even if the following settings are set in the code.
Feature.set (' id ',/* PRIMARY key value */);

Iv. Summary

For WFS-T operations, there are often problems with read-only and post-insert geometry fields being empty , and the reasons for these two problems are summarized below.

1. the possible causes of the read-only problem are: 1) The user does not have permission to edit the data table, 2) The geometry type of the data table in PostGIS is inconsistent with the geometry type of the feature to be edited, 3) is not set Role_ Anonymous or AJAX requests do not have a username and password set (Username/password), 4) The service level does not reach the thing operation, 5) The data table does not have a primary key (Id,primary key) set.

2. The reason that the geometry field is empty after inserting the feature is because the Geometry field name (GEOM) in the datasheet is inconsistent with the feature default name (geometry) and should be set in Openlayers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.