Radim Blazek wrote:
Here you could realy say: How awful! I cannot rename all OGR
datasources! Etc.
The problem here, is the same as with table names for attributes
(vector names may have characters not allowed in SQL ('.','-').
Any ideas for name mangling are welcome. Requirements for new name:
- similar to original
- simple enough for user
- using only chars accepted by SQL (for tables and columns)
Change all non-alphanumeric characters to underscores; prepend a
leading underscore if the name starts with a digit.
That satisfies all three stated conditions, although it doesn't
satisfy the (unstated) condition that distinct map names correspond to
distinct table/column names (no collisions).
There are two basic options for avoiding collisions:
1. Add a numeric suffix if the desired name is already in use; keep
incrementing the suffix until no collision occurs.
2. Use a scheme similar to URL-encoding, i.e. each non-alphanumeric
character (including underscores) is replaced by an underscore then
the two hex digits for the character's code.
3. Redefine the syntax of GRASS map names to match SQL; e.g. no case
sensitivity, and either:
a) no non-alphanumeric characters except underscore, or
b) all non-alphanumeric are equivalent (i.e. represented by an
underscore internally, so foo.bar and foo_bar are the same map).
All have disadvantages.
Option 1 is non-deterministic, in the sense that the translation
depends upon which maps already exist; also, you would have to store
the original name somewhere.
Option 2 is messy; particularly given that GRASS map names are
case-sensitive and SQL table/column names aren't, so you would also
have to encode all upper-case characters.
Option 3 means that anyone who wishes to preserve the names of their
existing maps loses.
> Now I have the next problem:
>
> g.rename vect=cp_clean,cp
> WARNING: Vectors are not supported by g.rename
>
> Is there another way to rename vector files in 5.1 ?
Would it be a problem to do g.copy + g.remove?
As I mentioned in code:
/* Vectors are not supported because I don't know how should work:
* 1. Should be all attribute tables renamed?
* 2. Should be all attribute tables moved to current default driver/database?
* 3. Should be PostGis tables renamed?
* 4. Should be PostGis tables moved to current default PostGis database? */
Treat vector maps like reclassed rasters. I.e. a vector map is
basically a file which tells you where to get the actual data from.
This satisfies the "store the original name somewhere" requirement of
option 1 above.
g.rename would work the same way as for other maps, i.e. it renames
the file/directory.
--
Glynn Clements <glynn.clements@virgin.net>