如何使用命令行在 Geoserver 中创建 SQL 视图

how to create SQL View in Geoserver with command line

下面是我用的代码,没用

curl -v -u admin:geoserver -XPUT -H 'Content-type: text/xml' -d
'<featureType>
<name>h12v10_locations_20ztesting</name>
<nativeName>h12v10_locations_20ztesting</nativeName>
<srs>EPSG:4326</srs>
<metadata><entry>
<virtualTable><name>h12v10_locations_20ztesting</name>
<sql>select gid, poly_label, data_score, data_time, year, the_geom
from h12v10_locations_2002
order by gid asc</sql>
<keyColumn>feature_id</keyColumn>
<geometry><name>the_geom</name><type>POINT</type><srid>4326</srid></geometry>
</virtualTable></entry></metadata></featureType>'
http://localhost:8080/geoserver/rest/layers/cite:h12v10_locations_20ztesting.xml

我想使用sql视图而不是创建图层是因为当我更新数据是PostGIS时,客户端检索的数据条目的顺序会改变。例如,当我更新 id=1 时,检索到的第一个条目将从 id=1

变为 id=2

经过反复试验,我找到了解决方案^_^

curl -v -u admin:geoserver -XPOST -H 'Content-type: text/xml' -d '
<featureType>
<name>h12v10_locations_2004new</name>
<nativeName>h12v10_locations_2004new</nativeName>
<namespace>
<name>cite</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://arizona-umh.cs.umn.edu:8080/geoserver/rest/namespaces/cite.xml" type="application/xml"/>
</namespace>
<title>h12v10_locations_2004new</title>
<keywords>
<string>features</string>
<string>h12v10_locations_2004new</string>
</keywords>
<srs>EPSG:4326</srs>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
<enabled>true</enabled>
<metadata>
<entry key="cachingEnabled">false</entry>
<entry key="JDBC_VIRTUAL_TABLE">
<virtualTable>
<name>h12v10_locations_2004new</name>
<sql>select gid, poly_label, data_score, data_time, year, the_geom from h12v10_locations_2004 order by gid asc</sql>
<escapeSql>false</escapeSql>
<keyColumn>gid</keyColumn>
<geometry>
<name>the_geom</name>
<type>Point</type>
<srid>4326</srid>
</geometry>
</virtualTable>
</entry>
</metadata>
<store class="dataStore">
<name>AlwaysShen</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://arizona-umh.cs.umn.edu:8080/geoserver/rest/workspaces/cite/datastores/AlwaysShen.xml" type="application/xml"/>
</store>
<maxFeatures>0</maxFeatures>
<numDecimals>0</numDecimals>
</featureType>'
http://localhost:8080/geoserver/rest/workspaces/cite/datastores/AlwaysShen/featuretypes/

希望这可以帮助那些花费数小时和数天谷歌搜索但没有找到真正解决这个特定问题的人:)