lundi 10 décembre 2007

What you need to use these functionalities

-





If you want to use these functionalities, and store 3D models in PostGIS, you first must have an installation of postgreSQL. You can get it on its website.


You also must install the following softwares:



  • PROJ4

Proj4 is a Cartographic Projections Library. You can download it on its website



  • GEOS

Geometry Engine Open Source is a library of geometry computation

You must install the version which is available on this blog if you want to use the 3D functionalities.



download GEOS




  • POSTGIS

A plugin for PostgreSQL which allows to store geographic data.
You also need the version available on this blog to use the 3D functionalities.



download PostGIS







After installing PostgreSQL, you must install the other softwares in the following order:


  1. PROJ4
  2. GEOS
  3. PostGIS.




  • INSTALLATION OF PROJ4:


execute these commands in the root directory:



_____________________

./configure
make
sudo make install
sudo ldconfig
_____________________







  • INSTALLATION OF GEOS


execute these commands in the root directory:



_____________________

./configure

make
sudo make install
sudo ldconfig
_____________________






  • INSTALLATION OF POSTGIS


execute these commands in the root directory:



______________________________________________

./configure --with-proj --with-geos --with-pgsql

make
sudo make install
______________________________________________





Now, you're ready to store 3D models in PostGIS.





-

mercredi 5 décembre 2007

X3D export

-




Another export function I decided to create is asx3d(). X3D is the VRML successor and describes an XML syntax. So it's a 3D format which is fine to use in a web environment.


This function is available for:
  • POINT
  • MULTIPOINT
  • LINESTRING
  • MULTILINESTRING
  • POLYGON
  • MULTIPOLYGON
  • TIN
  • POLYHEDRALSURFACE



Here are some example queries of its use:



  • POINT/MULTIPOINT LINESTRING/MULTILINESTRING

___________________________________________________________________

SELECT asx3d('POINT(1 2 3)');


SELECT asx3d('MULTIPOINT(1 2 3, 4 5 6)');


SELECT asx3d('LINESTRING(1 2 3, 4 5 6)');


SELECT asx3d('MULTILINESTRING((1 2 3, 4 5 6), (0 0 0, 5 4 6))');
___________________________________________________________________








  • TIN and POLYHEDRALSURFACE:


______________________________________________________________________________________________________________

SELECT asx3d('TIN(((0 0 0, 1 0 0 , 0 1 0, 0 0 0)),((1 0 0, 0 0 1, 0 1 0, 1 0 0)))');


SELECT asx3d('POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)))');
______________________________________________________________________________________________________________













PGSQL2X3D command:




I also developed a command which creates x3d files by exporting geometries from PostGIS.


Here is the help of this command:






__________________________________________________________

USAGE: pgsql2x3d [options] database [schema.]table
pgsql2x3d [options] database subquery

OPTIONS:
-f filename
Use this option to specify the name of the file to create.
If not present, the result will be printed on stdout.
-h host
Allows you to specify connection to a database on a machine other than the default.
-p port
Allows you to specify a database port other than the default.
-P password
Connect to the database with the specified password.
-u user
Connect to the database as the specified user.
-g geometry_column
Specify the geometry column to be exported. This option is necessary.
-t texture_name_column
Specify the texture name column to be exported.
-uv texture_coordinates
Specify the texture coordinates column to be exported.
!!!: If one of -t or -uv option is given, the other one must be given too.
-pos position
Specify the observator's position at the beginning.
-gc ground_color
Specify the ground color. (for example : '-gc 0.34 0.7 0.98')
-sc sky_color
Specify the sky color.
-fc faces_color
Specify the color of faces which are not textured.
-?
Display this help screen.

If you give a subquery instead of a table name in parameter, the -g -t and -uv options
must be the names of the alias you give in the subquery.
Example:
pgsql2x3d -g geom -t tex -uv uvcoord -f testfile mydatabase 'SELECT ST_RotateX(the_geom, 2)
AS geom, the_texture AS tex, coorduv AS uvcoord from mytable'

__________________________________________________________









EXAMPLES:




In these examples the names of the database, the table, the geometry_column, the texture_column and the texture_coordinates column are respectively MABASE mytable the_geom, the_texture and coorduv.



  • simple X3D export:

_______________________________________________________________

pgsql2x3d -u postgres -f testfile -g the_geom MABASE mytable
_______________________________________________________________



If you execute this command, you'll see see this in your window



_________________________________

ask for connection to MABASE

connexion ok
query ok
connexion closed
file testfile.x3d has been created
_________________________________





You need an X3D viewer to see testfile.x3d. X3D is the successor of VRML, so, most of VRML viewers works for X3D too. You can use for example freewrl which is a free software you can get here.



By executing this command:

____________________

freewrl testfile.x3d

____________________




you'll see this:









  • X3D export with textures:

_____________________________________________________________________________________________

pgsql2x3d -u postgres -f testfile -g the_geom -t the_texture -uv coorduv MABASE mytable
_____________________________________________________________________________________________



If you execute this command, you'll see see this in your window



_________________________________

ask for connection to MABASE

connexion ok
query ok
connexion closed
file testfile.x3d has been created
_________________________________







By executing this command


____________________

freewrl testfile.x3d
____________________


you'll see this:










including X3D in a web browser:





An advantage of X3D format is that it's easy to use in a web environment because of its XML syntax.



Here is an example with two files you can get here. If you place them on a server, change the path of the file x3d.php in the index.htm one and put the query that interests you, you can get this result in a web browser at the right url:







Unfortunately, x3d plugins for web browthers aren't really competitive for now. The best solution seems to be the use of FLUX Player, available on MediaMachines website, and Internet explorer on Windows. Indeed, consequents geometries could need about a minute to be loaded.





-