feature-pregeneralized_tutorial.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. .. _feature-pregeneralized_tutorial:
  2. Using the GeoTools feature-pregeneralized module
  3. ================================================
  4. .. warning:: The screenshots on this tutorial have not yet been updated for the 2.0.x user interface. But most all the rest of the information should be valid, and the user interface is roughly the same, but a bit more easy to use.
  5. Introduction
  6. ------------
  7. This tutorial shows how to use the geotools feature-pregeneralized module in GeoServer. The feature-pregeneralized module is used to improve performance and lower memory usage and IO traffic.
  8. .. note::
  9. Vector generalization reduces the number of vertices of a geometry for a given purpose. It makes no sense drawing a polygon with 500000 vertices on a screen. A much smaller number of vertices is enough to draw a topological correct picture of the polygon.
  10. This module needs features with already generalized geometries, selecting the best fit geometry on demand.
  11. The full documentation is available in :geotools:`GeoTools Pregeneralized Plugin <library/data/pregeneralized.html>` documentation.
  12. This tutorial will show two possible scenarios, explaining step by step what to do for using this module in GeoServer.
  13. Getting Started
  14. ---------------
  15. First, find the location of the GEOSERVER_DATA_DIR. This info is contained in the log file when starting GeoServer.::
  16. ----------------------------------
  17. - GEOSERVER_DATA_DIR: /home/mcr/geoserver-1.7.x/1.7.x/data/release
  18. ----------------------------------
  19. Within this directory, we have to place the shape files. There is already a sub directory :file:`data` which will be used.
  20. Within this sub directory, create a directory :file:`streams`.
  21. Within :file:`{GEOSERVER_DATA_DIR}/data/streams` create another sub directory called :file:`0`. ( 0 meaning "no generalized geometries").
  22. This tutorial is based on a shape file, which you can download from here :download:`Streams <streams.zip>`.
  23. Unzip this file into :file:`{GEOSERVER_DATA_DIR}/data/streams/0`.
  24. Look for the :file:`WEB-INF/lib/` directory of your GeoServer installation. There must be a file called :file:`gt-feature-pregeneralized-{version}-jar`. This jar file includes a tool for generalizing shape files. Open a cmd line and execute the following::
  25. cd <GEOSERVER_DATA_DIR>/data/streams/0
  26. java -jar <GEOSERVER_INSTALLATION>/WEB-INF/lib/gt-feature-pregeneralized-{version}.jar generalize 0/streams.shp . 5,10,20,50
  27. You should see the following output::
  28. Shape file 0/streams.shp
  29. Target directory .
  30. Distances 5,10,20,50
  31. % |################################|
  32. Now there are four additional directories :file:`5.0` , :file:`10.0` , :file:`20.0` , :file:`50.0` . Look at the size of files with the extension :file:`shp` within these directories, increasing the generalization distance reduces the file size.
  33. .. note::
  34. The generalized geometries can be stored in additional properties of a feature or the features can be duplicated.
  35. Mixed variations are also possible. Since we are working with shape files we have to duplicate the features.
  36. There are two possibilities how we can deploy our generalized shape files.
  37. #. Deploy hidden (not visible to the user)
  38. #. Deploy each generalized shape file as a separate GeoServer feature
  39. Hidden Deployment
  40. ------------------
  41. First we need a XML config file
  42. .. code-block:: xml
  43. <?xml version="1.0" encoding="UTF-8"?>
  44. <GeneralizationInfos version="1.0">
  45. <GeneralizationInfo dataSourceName="file:data/streams/0/streams.shp" featureName="GenStreams" baseFeatureName="streams" geomPropertyName="the_geom">
  46. <Generalization dataSourceName="file:data/streams/5.0/streams.shp" distance="5" featureName="streams" geomPropertyName="the_geom"/>
  47. <Generalization dataSourceName="file:data/streams/10.0/streams.shp" distance="10" featureName="streams" geomPropertyName="the_geom"/>
  48. <Generalization dataSourceName="file:data/streams/20.0/streams.shp" distance="20" featureName="streams" geomPropertyName="the_geom"/>
  49. <Generalization dataSourceName="file:data/streams/50.0/streams.shp" distance="50" featureName="streams" geomPropertyName="the_geom"/>
  50. </GeneralizationInfo>
  51. </GeneralizationInfos>
  52. Save this file as :file:`geninfo_shapefile.xml` into :file:`{GEOSERVER_DATA_DIR}/data/streams`.
  53. .. note::
  54. The **dataSourceName** attribute in the XML config is not interpreted as a name, it could be the URL for a shape file or for a property file containing properties for data store creation (e. g. jdbc connect parameters). Remember, this is a hidden deployment and no names are needed. The only *official* name is the value of the attribute **featureName** in the **GeneralizationInfo** Element.
  55. Start GeoServer and go to :menuselection:`Config-->Data-->DataStores-->New` and fill in the form
  56. .. image:: createdatastore.png
  57. Press :guilabel:`Submit`.
  58. The next form you see is
  59. .. image:: editdatastore1.png
  60. .. note::
  61. **RepositoryClassName** and **GeneralizationInfosProviderClassName** have default values which suit for GeoTools, not for GeoServer. Change **GeoTools** to **GeoServer** in the package names to instantiate the correct objects for GeoServer. **GeneralizationInfosProviderParam** could be an URL or a datastore from the GeoServer catalog. A datastore is referenced by using *workspacename:datastorename*. This makes sense if you have your own implementation for the **GeneralizationInfosProvider** interface and this implementation reads the infos from a database.
  62. The configuration should look like this
  63. .. image:: editdatastore2.png
  64. Press :guilabel:`Submit`, afterward a form for the feature type opens.
  65. Alter the **Style** to *line*, **SRS** is *26713* and press the :guilabel:`Generate` button labeled by **Bounding Box**.
  66. .. image:: editfeaturestore1.png
  67. Afterward, press :guilabel:`Submit`, :guilabel:`Apply` and :guilabel:`Save`.
  68. Examine the result by pressing "**My GeoServer**, **Demo** and **Map Preview**. In this list there must be an entry **topp:GenStreams**. Press it and you will see
  69. .. image:: streams.png
  70. Now start zooming in and out and look at the log file of GeoServer. If the deployment is correct you should see something like this::
  71. May 20, 2009 4:53:05 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  72. INFO: Using generalizsation: file:data/streams/20.0/streams.shp streams the_geom 20.0
  73. May 20, 2009 4:53:41 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  74. INFO: Using generalizsation: file:data/streams/5.0/streams.shp streams the_geom 5.0
  75. May 20, 2009 4:54:08 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  76. INFO: Using generalizsation: file:data/streams/5.0/streams.shp streams the_geom 5.0
  77. May 20, 2009 4:54:09 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  78. INFO: Using generalizsation: file:data/streams/20.0/streams.shp streams the_geom 20.0
  79. Public Deployment
  80. ------------------
  81. First we have to configure all our shape files
  82. .. image:: streams_0_ds.png
  83. The **Feature Data Set ID** for the other shape files is
  84. #. Streams_5
  85. #. Streams_10
  86. #. Streams_20
  87. #. Streams_50
  88. .. image:: streams_0_ds2.png
  89. The **URL** needed for the other shape files
  90. #. ``file:data/streams/5.0/streams.shp``
  91. #. ``file:data/streams/10.0/streams.shp``
  92. #. ``file:data/streams/20.0/streams.shp``
  93. #. ``file:data/streams/50.0/streams.shp``
  94. .. image:: streams_0_ds4.png
  95. Each feature needs an **Alias**, here it is *streams_0*. For the other shape files use
  96. #. streams_5
  97. #. streams_10
  98. #. streams_20
  99. #. streams_50
  100. Check the result by pressing :guilabel:`My GeoServer`, :guilabel:`Demo` and :guilabel:`Map Preview`. You should see your additional layers.
  101. No we need another XML configuration file
  102. .. code-block:: xml
  103. <?xml version="1.0" encoding="UTF-8"?>
  104. <GeneralizationInfos version="1.0">
  105. <GeneralizationInfo dataSourceNameSpace="topp" dataSourceName="Streams_0" featureName="GenStreams2" baseFeatureName="streams" geomPropertyName="the_geom">
  106. <Generalization dataSourceNameSpace="topp" dataSourceName="Streams_5" distance="5" featureName="streams" geomPropertyName="the_geom"/>
  107. <Generalization dataSourceNameSpace="topp" dataSourceName="Streams_10" distance="10" featureName="streams" geomPropertyName="the_geom"/>
  108. <Generalization dataSourceNameSpace="topp" dataSourceName="Streams_20" distance="20" featureName="streams" geomPropertyName="the_geom"/>
  109. <Generalization dataSourceNameSpace="topp" dataSourceName="Streams_50" distance="50" featureName="streams" geomPropertyName="the_geom"/>
  110. </GeneralizationInfo>
  111. </GeneralizationInfos>
  112. Save this file as :file:`geninfo_shapefile2.xml` into :file:`{GEOSERVER_DATA_DIR}/data/streams`.
  113. Create the pregeneralized datastore
  114. .. image:: createdatastore2.png
  115. Now we use the **CatalogRepository** class to find our needed data stores
  116. .. image:: editdatastore3.png
  117. Last step
  118. .. image:: editfeaturestore2.png
  119. In the :guilabel:`Map Preview` you should find **topp:GenStreams2** and all other generalizations. Test in the same manner we
  120. discussed in the hidden deployment and you should see something like this in the GeoServer log::
  121. May 20, 2009 6:11:06 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  122. INFO: Using generalizsation: Streams_20 streams the_geom 20.0
  123. May 20, 2009 6:11:08 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  124. INFO: Using generalizsation: Streams_10 streams the_geom 10.0
  125. May 20, 2009 6:11:12 PM org.geotools.data.gen.PreGeneralizedFeatureSource logDistanceInfo
  126. INFO: Using generalizsation: Streams_10 streams the_geom 10.0
  127. Conclusion
  128. ----------
  129. This is only a very simple example using shape files. The plugin architecture allows you to get your data and generalizations from anywhere. The used dataset is a very small one, so you will not feel a big difference in response time. Having big geometries (in the sense of many vertices) and creating maps with some different layers will show the difference.