question about shp2tile

Zhonghai Wang zhonghaiw at GMAIL.COM
Sat May 20 02:27:39 PDT 2006


Hi Steve,

sorry for the delay. But at first I'm glad to tell you good news that it
works well. Thanks so much for the detailed analysis and being so patient
with me.

the only problem for me when I did that is: I did not make any subfolder for
the tiled shapefiles, and this stupid error makes things confusing.

P.S.> Steve, if I have now a large scanned paper map as jpeg format, and I
want to slice it again like the shapeflies, how do I do that?

zhonghai

20.05.2006

On 5/19/06, Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
>
> Zhonghai,
>
> Here is a log of what I did. I always make a directory to put the tiles
> into, woodland for this example.
>
> > woodbri at linus:~/test$ ls
> > CA_NAV_COUNTRY_region.dbf  CA_NAV_WOODLAND_region.prj
> > CA_NAV_COUNTRY_region.prj  CA_NAV_WOODLAND_region.qix
> > CA_NAV_COUNTRY_region.qix  CA_NAV_WOODLAND_region.shp
> > CA_NAV_COUNTRY_region.shp  CA_NAV_WOODLAND_region.shx
> > CA_NAV_COUNTRY_region.shx   test.rar
> > CA_NAV_WOODLAND_region.dbf
>
> make a dir for the tiles
>
> > woodbri at linus:~/test$ mkdir woodland
> > woodbri at linus:~/test$ shp2tile
> > Usage: shp2tile <options> <shapefile> <dest name>
> >   where <options> are:
> >    [-v|--version]      print version string and exit
> >    [-s|--no-stats]     do not print stats
> >    [-w|--no-write]     do not write output files
> >    [-r|--row] <n>      generate <n> rows in Y
> >    [-c|--col] <m>      generate <m> cols in X
> >    [-e|--square-ext]   adjust extent to produce square tiles
> >    [-q|--quadtree] <n> quadtree type of index (auto split tiles > n
> objects)
> >   <shapefile>          name of file to read and split into tiles
> >   <dest name>          output file names: <dest name>-<num>.<ext>
>
> check how big the shapfile is
>
> > woodbri at linus:~/test$ shpdump CA_NAV_WOODLAND_region | head
> > Shapefile Type: Polygon   # of Shapes: 9638
> >
> > File Bounds: (       6.055,      45.818,0,0)
> >          to  (      10.489,      47.808 ,0,0)
> >
> > Shape:0 (Polygon)  nVertices=62, nParts=1
> >   Bounds:(       7.602,      47.573, 0, 0)
> >       to (       7.627,      47.579, 0, 0)
> >      (       7.609,      47.578, 0, 0) Ring
> >      (       7.610,      47.578, 0, 0)
>
> check that I am working with the most recent version
>
> > woodbri at linus:~/test$ shp2tile -v
> > $Id: shp2tile.c,v 1.13 2005/12/05 22:38:08 woodbri Exp $
>
> run a test -w says down write tiles, just print stats
>
> > woodbri at linus:~/test$ shp2tile -r 3 -c 3 -w CA_NAV_WOODLAND_region.shp
> woodland/woodland
> > Shapefile Type: Polygon   # of Shapes: 9638
> >
> > File Bounds: (     6.055040,   45.818020)
> >          to  (   10.489220,   47.808380)
> >
> > Divided into 3 rows X 3 columns (dx, dy) = (    1.478060,    0.663453)
> >
> >  Index   Cell     Count      XMin         YMin         YMax         YMax
>
> >      0 [  0,  0]   1062     6.055040    45.818020     7.533100
> 46.481473
> >      1 [  0,  1]   1867     7.533100    45.818020     9.011160
> 46.481473
> >      2 [  0,  2]    556     9.011160    45.818020     10.489220
> 46.481473
> >      3 [  1,  0]    888     6.055040    46.481473     7.533100
> 47.144927
> >      4 [  1,  1]   1206     7.533100    46.481473     9.011160
> 47.144927
> >      5 [  1,  2]   2059     9.011160    46.481473    10.489220
> 47.144927
> >      6 [  2,  0]    100     6.055040    47.144927     7.533100
> 47.808380
> >      7 [  2,  1]   1413     7.533100    47.144927     9.011160
> 47.808380
> >      8 [  2,  2]    475     9.011160    47.144927    10.489220
> 47.808380
> >      9 [ global]     12     6.055040    45.818020    10.489220
> 47.808380
> >                --------
> >                    9638
> > Global cell contains: 0 objects.
>
> These are too small a cound so do the 2 x 2
>
> > woodbri at linus:~/test$ shp2tile -r 2 -c 2 -w CA_NAV_WOODLAND_region.shp
> woodland/woodland
> > Shapefile Type: Polygon   # of Shapes: 9638
> >
> > File Bounds: (     6.055040,   45.818020)
> >          to  (   10.489220,   47.808380)
> >
> > Divided into 2 rows X 2 columns (dx, dy) = (    2.217090,    0.995180)
> >
> >  Index   Cell     Count      XMin         YMin         YMax         YMax
>
> >      0 [  0,  0]   3096     6.055040    45.818020     8.272130
> 46.813200
> >      1 [  0,  1]   2751     8.272130    45.818020    10.489220
> 46.813200
> >      2 [  1,  0]   1679     6.055040    46.813200      8.272130
> 47.808380
> >      3 [  1,  1]   2107     8.272130    46.813200    10.489220
> 47.808380
> >      4 [ global]      5     6.055040    45.818020    10.489220
> 47.808380
> >                --------
> >                    9638
> > Global cell contains: 0 objects.
>
> Now really do the 2x2 and write the files
>
> > woodbri at linus:~/test$ shp2tile -r 2 -c 2  CA_NAV_WOODLAND_region.shp
> woodland/woodland
> > Shapefile Type: Polygon   # of Shapes: 9638
> >
> > File Bounds: (    8.272390,   46.764400)
> >          to  (   10.489220,   47.808380)
> >
> > Divided into 2 rows X 2 columns (dx, dy) = (     2.217090,    0.995180)
> >
> >  Index   Cell     Count      XMin         YMin         YMax         YMax
> >      0 [  0,  0]   3096     6.055040    45.909350     8.277650
> 46.859200
> >      1 [  0,  1]   2751     8.274860    45.818020    10.479450
> 46.834150
> >      2 [  1,  0]   1679     6.432630    46.783620     8.373900
> 47.613070
> >      3 [  1,  1]   2107     8.272390    46.764400    10.489220
> 47.808380
> >      4 [ global]      5     6.055040    45.818020    10.489220
> 47.808380
> >                --------
> >                    9638
> > Global cell contains: 5 objects.
>
> list the new files
>
> > woodbri at linus:~/test$ ls woodland/
> > woodland-0.dbf woodland-1.dbf woodland-2.dbf woodland-3.dbf
> woodland-4.dbf
> > woodland-0.shp woodland-1.shp woodland-2.shp woodland-3.shp
> woodland-4.shp
> > woodland-0.shx woodland-1.shx woodland-2.shx woodland-3.shx
> woodland-4.shx
>
> create the spatial indexes
>
> > woodbri at linus:~/test$ find woodland/ -name \*.shp -exec shptree {} \;
> > creating index of new  LSB format
> > creating index of new  LSB format
> > creating index of new  LSB format
> > creating index of new  LSB format
> > creating index of new  LSB format
>
> create the metatile input file
>
> > woodbri at linus:~/test$ find woodland/ -name \*.shp > woodland.in
>
> check the command syntax
>
> > woodbri at linus:~/test$ tile4ms
> >
> > usage: tile4ms <meta-file> <tile-file> [-tile-path-only]
> > <meta-file>     INPUT  file containing list of shapefile names
> >                 (complete paths 255 chars max, no extension)
> > <tile-file>     OUTPUT shape file of extent rectangles and names
> >                 of tiles in <tile-file>.dbf
> > -tile-path-only Optional flag.  If specified then only the path to the
> >                 shape files will be stored in the LOCATION field
> >                 instead of storing the full filename.
> >
> create the tileindex
>
> > woodbri at linus:~/test$ tile4ms woodland.in woodland-tile
> > Processed 5 of 5 files
>
> See what we have got
>
> > woodbri at linus:~/test$ ls
> > CA_NAV_COUNTRY_region.dbf  CA_NAV_WOODLAND_region.shx
> > CA_NAV_COUNTRY_region.prj  county
> > CA_NAV_COUNTRY_region.qix  test.rar
> > CA_NAV_COUNTRY_region.shp  woodland
> > CA_NAV_COUNTRY_region.shx  woodland-tile.dbf
> > CA_NAV_WOODLAND_region.dbf woodland-tile.shp
> > CA_NAV_WOODLAND_region.prj woodland-tile.shx
> > CA_NAV_WOODLAND_region.qix woodland.in
> > CA_NAV_WOODLAND_region.shp
>
> Oh, add spatial index to the tileindex
>
> > woodbri at linus:~/test$ shptree woodland-tile.shp
> > creating index of new  LSB format
>
> check the country file size
>
> > woodbri at linus:~/test$ shpdump CA_NAV_COUNTRY_region.shp | head
> > Shapefile Type: Polygon   # of Shapes: 5
> >
> > File Bounds: (       5.956,      45.818,0,0)
> >          to  (      10.492,      47.808,0,0)
> >
> > Shape:0 (Polygon)  nVertices=15977, nParts=3
> >   Bounds:(       5.956,      45.818, 0, 0)
> >       to (      10.492,      47.808, 0, 0)
> >      (      10.047,      46.544, 0, 0) Ring
> >      (      10.047,      46.543, 0, 0)
>
> country file is too small to index.
>
> Make a mapfile to view the results:
>
> MAP
>    EXTENT  5.956  45.818  10.492  47.808
>    IMAGECOLOR 240 204 102
>    SHAPEPATH /u/test
>    SIZE 600 400
>    UNITS DD
>
>    LAYER
>      NAME "administration"
>      GROUP "country"
>      STATUS DEFAULT
>      DATA "CA_NAV_COUNTRY_region"
>      TYPE POLYGON
>      DEBUG ON
>      CLASS
>        NAME "country"
>        STYLE
>          COLOR 255 255 204
>        END
>      END
>    END
>
>    LAYER
>      NAME "woodland"
>      GROUP "country"
>      STATUS DEFAULT
>      TILEINDEX "woodland-tile"
>      TYPE POLYGON
>      DEBUG ON
>      CLASS
>        NAME "woodland"
>        STYLE
>          COLOR 102 255 102
>        END
>      END
>    END
> END
>
> Here is a url to see the results.
>
>
> http://swoodbridge.com/linus/cgi-bin/mapserv461?mode=map&map=/u/test/test.map
>
> you should be able to do the same and get the same results.
>
> -Steve
>
> Zhonghai Wang wrote:
> > Hi Steve,
> >
> > the example shapefiles are enclosed in the attachment as a .rar file,
> > the coordinate system is swiss national system, epsg:21781 or
> world:CH1903.
> >
> > specify any parameter values won't work, only using default 2*2 images
> > can be rendered, as I said, only part of the map extent.
> >
> > thanks
> >
> > zhongahi
> >
> > On 5/18/06, *Stephen Woodbridge* < woodbri at swoodbridge.com
> > <mailto:woodbri at swoodbridge.com>> wrote:
> >
> >     Zhonghai,
> >
> >     Can you send me the forest and settlement shap files.
> >
> >     tar czf data-for-steve.tgz forest.* settlement.*
> >
> >     and email me the file. I will take a look. It might be a bug.
> >
> >     -Steve
> >
> >     Zhonghai Wang wrote:
> >      > Hi All,
> >      >
> >      > with the shp2tile command, I get some strange results:
> >      >
> >      > data -- forests.shp (includes 9638 polygons) -- only used for
> example
> >      >
> >      > after performing the commands shp2tile, tile4ms and shptree, this
>
> >     time I
> >      > perform additionally the command shptreevis for each shapefile,
> >     and I
> >      > get the quadtree views for the shapefiles. When I open the
> >      > forest_quad.shp and overlay the tileindex_quad.shp on it with
> >     QGIS, the
> >      > tileindex_quad.shp covers only a small part of the whole forest
> map
> >      > extent, and the returned map image is rendered in the same way,
> >     forest
> >      > covers only a small part of the map extent.
> >      >
> >      > P.S>I tile the shapefile without any additional parameters:
> shp2tile
> >      > forests.shp ff.shp  --  it gives 2*2 tiling
> >      >
> >      > two pictures are enclosed in the attachment.
> >      >
> >      > where:
> >      > 1. quadtree.jpeg -- the quadtree shapefiles opened in QGIS;
> >      > 2. map.jpeg -- map image rendered with TILEINDEX "tileindex" and
> >      > TILEITEM "LOCATION";
> >      > 3. forest.jpeg -- forest area rendered with original forests.shp
> >     file.
> >      >
> >      > thanks for any further info
> >      >
> >      > zhonghai
> >      >
> >      > On 5/18/06, *Zhonghai Wang* < zhonghaiw at gmail.com
> >     <mailto:zhonghaiw at gmail.com>
> >      > <mailto: zhonghaiw at gmail.com <mailto:zhonghaiw at gmail.com>>>
> wrote:
> >      >
> >      >     Hi Steve,
> >      >
> >      >     I've tried again like you said, this time I get something,
> >     but still
> >      >     no map images are rendered.
> >      >
> >      >     the version is exactly the same, updated version.
> >      >
> >      >     First test example:
> >      >
> >      >     data -- admin.shp (administration area, which includes 5
> >     polygons)
> >      >
> >      >     ****
> >      >     when performing shp2tile command, no parameters are set,  and
> by
> >      >     default the shapefile is sliced into 2*2+1 shapefiles. With
> the
> >      >     following layer object definition, map image is drawn:
> >      >
> >      >     LAYER
> >      >         NAME "administration"
> >      >         GROUP "country"
> >      >         STATUS DEFAULT
> >      >         TILEINDEX "index"
> >      >         TILEITEM "LOCATION"
> >      >         TYPE POLYGON
> >      >         DEBUG ON
> >      >         TRANSPARENCY ALPHA
> >      >         CLASS
> >      >           NAME "woodland"
> >      >           STYLE
> >      >             COLOR 204 204 255
> >      >             ANTIALIAS TRUE
> >      >           END
> >      >         END
> >      >       END
> >      >     **********
> >      >     Second test example:
> >      >
> >      >     data -- settlement.shp, which contains 2155664 polygons
> >      >
> >      >     ****
> >      >     when performing shp2tile command for this shapefile, I set
> 10*10,
> >      >     each slice contians therefore about 21557 polygons. It's also
> ok
> >      >     with tile4ms and shptree commands.
> >      >
> >      >     hm... seems exciting...
> >      >
> >      >     but, with this layer object definition no settlements are
> drawn :
> >      >
> >      >     LAYER
> >      >         NAME "Settlement"
> >      >         GROUP "settlements"
> >      >         STATUS DEFAULT
> >      >         TILEINDEX "settlementindex"
> >      >         TILEITEM "LOCATION"
> >      >         MAXSCALE 100000
> >      >         TYPE POLYGON
> >      >         DEBUG ON
> >      >         TRANSPARENCY ALPHA
> >      >         CLASS
> >      >           NAME "SM"
> >      >           STYLE
> >      >             COLOR 153 153 102
> >      >             ANTIALIAS TRUE
> >      >           END
> >      >         END
> >      >       END
> >      >     *****
> >      >     I have now really no idea where the problems should be.
> >      >
> >      >     Steve, any clues?
> >      >
> >      >     thanks for your info.
> >      >
> >      >     zhonghai
> >      >
> >      >     On 5/18/06, *Stephen Woodbridge* < woodbri at swoodbridge.com
> >     <mailto:woodbri at swoodbridge.com>
> >      >     <mailto: woodbri at swoodbridge.com
> >     <mailto:woodbri at swoodbridge.com>>> wrote:
> >      >
> >      >         Zhonghai Wang wrote:
> >      >>  Hi guys,
> >      >>
> >      >>  I've tried to make a efficient map layer with the commands
> >      >         shp2tile,
> >      >>  tile4ms, and shptree, but something seems not right, because
> >      >         MapServer
> >      >>  can not draw the maps. I've made a test in a seperate folder,
> >      >         and I've
> >      >>  done the following processes:
> >      >>
> >      >>  ***
> >      >>  data -- Forests.shp (for a country)
> >      >>  ***
> >      >>  1. >shp2tile -r 50 -c 50 Forests.shp Forests_Test.shp
> >      >>  >>>results for this step: shp, shx, and dbf files, there is no
> >      >         prj file
> >      >>  for the output file
> >      >>  >>>error info on the console: failed to create shp
> >      >         Forests_Test.shp -1833
> >      >
> >      >         This is likely because you are trying to create 2501
> >     files (50 x
> >      >         50 + 1)
> >      >         and they all half to be open at the same time for this
> >     mode so you
> >      >         likely ran into a process file handle limit. Also how
> >     many point
> >      >         do you
> >      >         have in this layer? What is the value of Num_points/2500,
>
> >     this
> >      >         number
> >      >         should not be smaller than 8000 - 10000.
> >      >
> >      >>  2. >tile4ms ---- get the tileindex.shx, tileindex.shp and
> >      >         tileindex.dbf
> >      >>  files for the Forests_Test.shp, there is still no prj file for
> >      >         tileindex.shp
> >      >>  >>>no error messages appear at this step
> >      >
> >      >         There are no prj files created. Mapserver does not use
> them.
> >      >
> >      >>  3. >shptree -- to genetare .qix file for all shapefiles in
> >      >         this subfolder
> >      >>  >>> results for this step: Forests.qix, Forests_Test.qix, and
> >      >         tileindex.qix
> >      >>  >>>no error info on the console
> >      >>
> >      >>  but, only if I set DATA "Forests" in the layer object the map
> >      >         will be
> >      >>  rendered, others like DATA "Forests_Test" or TTILEINDEX
> >      >         "tileindex"
> >      >>  TILEITEM "location" do not work, the server simply sends back
> >      >         a blank
> >      >>  image.
> >      >>
> >      >>  did I make any mistakes or it really do not work well. (I am
> >      >         using MS4W
> >      >>  4.8.1)
> >      >>
> >      >>  I guess some errors occur when I perform the command shp2tile.
> >      >
> >      >         What version of shp2tile are you using?
> >      >
> >      >         woodbri at carto:/data/mdata$ ~/dev/shptools/shp2tile -v
> >      >         $Id: shp2tile.c,v 1.13 2005/12/05 22:38:08 woodbri Exp $
> >      >
> >      >         If it does not respond with the Id string above you need
> to
> >      >         upgrade as
> >      >         there is a serious crashing bug for point data in the
> earlier
> >      >         version if
> >      >         you are using the -q option. It should work for the row
> col
> >      >         option, just
> >      >         try to decrease the number of tiles.
> >      >
> >      >         Also if you do not have something like R x C files in
> >     your directory
> >      >         then the process failed. For the row col option you can
> also
> >      >         specify
> >      >         --no-write to just get a stats report of how the data is
> put
> >      >         into the tiles.
> >      >
> >      >         -Steve
> >      >
> >      >>  thanks for any further info.
> >      >>
> >      >>  zhonghai
> >      >>
> >      >>  On 5/18/06, *Zhonghai Wang* < zhonghaiw at gmail.com
> >     <mailto:zhonghaiw at gmail.com>
> >      >         <mailto: zhonghaiw at gmail.com <mailto:zhonghaiw at gmail.com
> >>
> >      >>  <mailto:zhonghaiw at gmail.com <mailto: zhonghaiw at gmail.com>
> >     <mailto: zhonghaiw at gmail.com <mailto:zhonghaiw at gmail.com>>>> wrote:
> >      >>
> >      >>     Hi Bob, Steve,
> >      >>
> >      >>     thank you very much for all these helpful clues, now I
> >      >         think I've
> >      >>     got the points of the shp2tile command, it's really a good
> >      >         tool to
> >      >>     slice shapefile.
> >      >>
> >      >>     zhonghai
> >      >>
> >      >>     On 5/18/06, *Stephen Woodbridge* < woodbri at swoodbridge.com
> >     <mailto:woodbri at swoodbridge.com>
> >      >         <mailto: woodbri at swoodbridge.com
> >     <mailto:woodbri at swoodbridge.com>>
> >      >>     <mailto: woodbri at swoodbridge.com
> >     <mailto:woodbri at swoodbridge.com>
> >      >         <mailto: woodbri at swoodbridge.com
> >     <mailto: woodbri at swoodbridge.com> >>> wrote:
> >      >>
> >      >>         Zhonghai Wang wrote:
> >      >> >  Hi folks,
> >      >> >
> >      >> >  I have a large shapefile, now I am trying to use shp2tile
> >      >>         command to
> >      >> >  slice it into pieces, with -r and -c is ok, but I do not
> fully
> >      >> >  understand the -q parameter, what does it actually mean? and
> >      >>         what number
> >      >> >  should a use for this parameter normally?
> >      >> >
> >      >> >  or something like this? -- >shp2tile -q 10000 input_shapefile
> >      >> >  output_shapefile
> >      >>
> >      >>         Hi Zhonghai,
> >      >>
> >      >>         The -r -c option breaks the extents of your shapefile
> >      >         into R x C
> >      >>         rows
> >      >>         and columns and then tries to fit the objects into the
> best
> >      >>         tile. I any
> >      >>         tile crosses a tile boundary by 5-10% then it is put
> >      >         into a
> >      >>         "supertile"
> >      >>         the could be the same extents as the original shape
> >      >         file. So
> >      >>         typically
> >      >>         you will end up with r X c + 1 tiles.
> >      >>
> >      >>         The -q N option splits the extents in half either
> >      >         vertically or
> >      >>         horizontally and then sorts the objects into the 2
> >      >         halves or put
> >      >>         them in
> >      >>         a supertile. Then if the either of the two halves has
> >      >         more than N
> >      >>         objects it is again split in half and this continues
> >      >         until all files
> >      >>         have less than N objects. This can cause some strange
> >      >         effects
> >      >>         like tiles
> >      >>         with 1 or a small number of objects and most tiles will
> >      >         have
> >      >>         less than N
> >      >>         objects in them. Since this algorithm tends to
> >      >         spatially cluster
> >      >>         objects
> >      >>         in a file, there is a good chance that if you need the
> >      >         file that
> >      >>         all or
> >      >>         most objects in the file will be used.
> >      >>
> >      >>         I recommend trying numbers like 10,000 and 20,000 as
> >      >         you initial
> >      >>         tries.
> >      >>         I think you should probably not use numbers less then
> >      >         8000, but
> >      >>         it is
> >      >>         really up to you to try and measure the results to find
> >      >         what
> >      >>         works best
> >      >>         for your data.
> >      >>
> >      >>         -Steve W.
> >      >>
> >      >>
> >      >>
> >      >
> >      >
> >      >
> >      >
> >      >
> >
> ------------------------------------------------------------------------
> >      >
> >      >
> >      >
> >
> ------------------------------------------------------------------------
> >
> >      >
> >      >
> >      >
> >
> ------------------------------------------------------------------------
> >      >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060520/9d9512fd/attachment.htm>


More information about the MapServer-users mailing list