Thread: Any support for spatial and .NET?


Permlink Replies: 25 - Pages: 2 [ 1 2 | Next ] - Last Post: Feb 12, 2008 4:17 AM Last Post By: wateenmooiedag
lagrone

Posts: 4
Registered: 04/13/00
Any support for spatial and .NET?
Posted: Apr 26, 2004 8:35 AM
Click to report abuse...   Click to reply to this thread Reply
I have been developing in Microsoft .NET, using C# and managed and unmanaged C++. Is there any data provider for .NET that will allow me to work with spatial data? Are there any examples?

If not, can someone point me to the best examples for interacting with spatial data using C++?

I'm continuing my search, but thought you guys might be able to point me in a good direction quicker.

Thanks

Ron
daniel.abugov@o...

Posts: 1,824
Registered: 01/10/01
Re: Any support for spatial and .NET?
Posted: Apr 26, 2004 1:34 PM   in response to: lagrone in response to: lagrone
Click to report abuse...   Click to reply to this thread Reply
currently there is OCCI, which is a c++ interface. ODP.NET will hopefully support spatial in the next release. There is a current workaround that involves changing spatial data to a clob type, but it is not an elegant solution.
lagrone

Posts: 4
Registered: 04/13/00
Re: Any support for spatial and .NET?
Posted: Apr 26, 2004 1:41 PM   in response to: lagrone in response to: lagrone
Click to report abuse...   Click to reply to this thread Reply
Anyone got any pointers to useful OCCI and spatial examples?

I've been searching for .NET, I'll switch my searches to be for OCCI.
kivriel

Posts: 32
Registered: 02/26/02
Re: Any support for spatial and .NET?
Posted: Apr 27, 2004 11:53 PM   in response to: lagrone in response to: lagrone
Click to report abuse...   Click to reply to this thread Reply
Maybe you can use OO4O, which is based on COM ?
knox@ps.edu.pl

Posts: 3
Registered: 04/06/04
Re: Any support for spatial and .NET?
Posted: Apr 28, 2004 9:47 PM   in response to: kivriel in response to: kivriel
Click to report abuse...   Click to reply to this thread Reply
hi did sth like that:

  string constr = "User Id=scott;Password=tiger;Data Source=oracle";
  OracleConnection con = new OracleConnection(constr);
  con.Open();

  OracleCommand cmd = new OracleCommand("select * from cola_markets", con);
  cmd.XmlCommandType =  OracleXmlCommandType.Query;
  cmd.CommandText = query;
  cmd.BindByName = true;

  int rows = cmd.ExecuteNonQuery();

  XmlReader xmlReader =  cmd.ExecuteXmlReader();
  XmlDocument xmlDocument = new XmlDocument();
  xmlDocument.PreserveWhitespace = true;
  xmlDocument.Load(xmlReader);
  return xmlDocument;

and it returns sth like this:

<?xml version="1.0" encoding="utf-8"?>
<ROWSET>
  <ROW>
    <MKT_ID>1</MKT_ID>
    <NAME>cola_a</NAME>
    <SHAPE>
      <SDO_GTYPE>2003</SDO_GTYPE>
      <SDO_ELEM_INFO>
        <NUMBER>1</NUMBER>
        <NUMBER>1003</NUMBER>
        <NUMBER>3</NUMBER>
      </SDO_ELEM_INFO>
      <SDO_ORDINATES>
        <NUMBER>1</NUMBER>
        <NUMBER>1</NUMBER>
        <NUMBER>5</NUMBER>
        <NUMBER>7</NUMBER>
      </SDO_ORDINATES>
    </SHAPE>
  </ROW>
  <ROW>
    <MKT_ID>2</MKT_ID>
    <NAME>cola_b</NAME>
    <SHAPE>
      <SDO_GTYPE>2003</SDO_GTYPE>
      <SDO_ELEM_INFO>
        <NUMBER>1</NUMBER>
        <NUMBER>1003</NUMBER>
        <NUMBER>1</NUMBER>
      </SDO_ELEM_INFO>
      <SDO_ORDINATES>
        <NUMBER>5</NUMBER>
        <NUMBER>1</NUMBER>
        <NUMBER>8</NUMBER>
        <NUMBER>1</NUMBER>
        <NUMBER>8</NUMBER>
        <NUMBER>6</NUMBER>
        <NUMBER>5</NUMBER>
        <NUMBER>7</NUMBER>
        <NUMBER>5</NUMBER>
        <NUMBER>1</NUMBER>
      </SDO_ORDINATES>
    </SHAPE>
  </ROW>
...

but i have problems when i want to fill dataset with this data :|
oh, i wonder if sb have any experience in storing gml (geography markup language) in oracle db.

__
greetings
Bartosz Machocki
jasond2

Posts: 2
Registered: 09/07/05
Re: Any support for spatial and .NET?
Posted: Sep 7, 2005 8:53 AM   in response to: knox@ps.edu.pl in response to: knox@ps.edu.pl
Click to report abuse...   Click to reply to this thread Reply
I've been using the XmlDocument and XmlTextReader technique for a while now to query spatial tables and it's very fast but you need to use a XmlTextReader to get good performance and skip the XmlDocument.Load() step. Never could figure out how to load a data table either. OCI was another method we tried to use but it proved very painful in .NET so we went with this Xml approach.

Inserting/updating large geometry objects, or using SDO_FILTER with a large transient polygons with hundreds of points, is a pain though when you have large linestrings of ordinates that are > 2048 characters in length. Eg.

select T.ID, T.GEOM from TABLE T where SDO_FILTER(T.GEOM, MDSYS.SDO_GEOMETRY(...some really big polygon...), 'mask=anyinteract') = 'TRUE';

This statement will fail with ORA-03113 errors and access violations/core dumps reported in the logs if the length of the SQL statement is too long, which for me maxes out at about 200 points.

There doesn't appear to be a way in ODP.NET to bind a VARRAY of numbers representing the SDO_ORDINATE_ARRAY(), or bind an SDO_GEOMETRY object itself, to your SQL statement.

Does anyone know which release Oracle plans to support objects as bind variables in ODP.NET?
sgreener

Posts: 439
Registered: 03/25/98
Re: Any support for spatial and .NET?
Posted: Sep 7, 2005 5:33 PM   in response to: jasond2 in response to: jasond2
Click to report abuse...   Click to reply to this thread Reply
I have programmed OO4O in VB6 and it works quite well (read and write)
but the COM wrapper over the Oracle Objects is quite slow. I got some
very, very acceptable (read) performance by using OraCustomDynaset()
and breaking up the Sdo_Geometry into its constituent parts on the server
by doing the following:

select
a.shape.sdo_gtype,
a.shape.sdo_srid,
a.shape.sdo_elem_info,
a.shape.sdo_ordinates,.....
from <table> a

(With variations for SDO_POINT.)

Of course, this is not good if you want to do a SELECT ... FOR UPDATE.
Still, for fast read only access it is quite good.

Wrt access in ODP.NET I add in my vote for some decent support for
all Oracle Spatial vector objects in the ODP provider.

For those using 10g, instead of using the XML engine (nice approach)
you could use the TO_WKT() (returns CLOB) or TO_WKB() (returns BLOB)
and then process them accordingly in your .NET cient application (there are
some "GIS" development kits around - like TatukGIS's DK - that will map
WKT/WKB into Shapes (for shapefiles) etc.

For read only, you could push the conversions back into the database via materialized views with function based indexes eg

Create Materialized View WKT_VIEW
<mv properties>
AS
SELECT gid, a.geom.to_wkt()
FROM <my table> a;

Then create a function based index over the WKT/WKB column using an SDO_GEOMETRY constructor that takes the WKT/WKB and the SRID
as its elements.

In fact, you could simply store the WKT/WKB on the base table alongside the Sdo_Geometry and use triggers to keep them synchronised.

So, with WKT/WKB at 10g, you can do your insert,update as follows...

insert into <table> a set a.shape = MDSYS.SDO_GEOMETRY(:WKT, SRID);

Using WKT/WKB would give you maximum portability across SpatialDBs (eg MySQL, PostGIS etc) if this is what you are hoping to do in the future.

S.
daniel.abugov@o...

Posts: 1,824
Registered: 01/10/01
Re: Any support for spatial and .NET?
Posted: Sep 11, 2005 4:08 PM   in response to: jasond2 in response to: jasond2
Click to report abuse...   Click to reply to this thread Reply
Hi,
This cannot be construed as a commitment, but I've heard recently that beta for odp.net that includes object (and spatial) support should be before the end of the year.
Dan
sgreener

Posts: 439
Registered: 03/25/98
Re: Any support for spatial and .NET?
Posted: Sep 24, 2005 1:03 AM   in response to: daniel.abugov@o... in response to: daniel.abugov@o...
Click to report abuse...   Click to reply to this thread Reply
Dan,

Now this is good news.

I know you can't let the cat out of the bag, but I do hope that the ODP.NET
stuff provides some good constructor and accessor functions for Sdo_Geometry
so we don't have to write our own! What I mean by this is that a programmer
shouldn't have to know the details of how the Sdo_Elem_Info array is organised
and interpreted, or how the ordinate array is arranged. This would make data
import/export so much easier.

It would also be nice if the ODP.NET API included some constructors/accessors
for WKB and WKT manipulations (other than having to have the server do the
computations via to_wkt()/from_wkt() etc.

S.
patrick.van.dij...

Posts: 70
Registered: 04/26/05
Re: Any support for spatial and .NET?
Posted: Oct 3, 2005 6:01 AM   in response to: sgreener in response to: sgreener
Click to report abuse...   Click to reply to this thread Reply
You could check CoreLabs, which provide access to Oracle Objects from .NET.
They do have a Data Provider capable of quering Objects, although it's not too performant,
this might help you out for the time being.
fjlee

Posts: 9
Registered: 01/10/01
Re: Any support for spatial and .NET?
Posted: Nov 22, 2005 11:26 AM   in response to: lagrone in response to: lagrone
Click to report abuse...   Click to reply to this thread Reply
Hi Everyone,

If ODP.NET supports SDO_GEOMETRY object type mapping, what type(s) of the attributes in a corresponding C# or VB type/class do you perfer?

For example, if we use these instances with the System.Drawing.Drawing2D for vector graphic functionality, the ordinates attribute would be better represented as PathData instance, which encapsulates an array of points.

Or a vector of double will do for the ordinates attribute, as in JGeometry Java class?

Another issues is whether we should do safe type mapping to perserve data precision and null semantics of Oracle NUMBERs.

OracleDataAdapter Safe type mapping background info:

OracleDecimal Type and .NET Decimal Type:

OracleDecimal can store up to 38 precision, while the .NET Decimal datatype can only hold up to 28 precision. When accessing the OracleDecimal.Value property from an OracleDecimal that has a value greater than 28 precision, loss of precision can occur.
To retrieve the actual value of OracleDecimal, use the OracleDecimal.ToString() method.

If NUMBER is stored as.NET Decimal or double, precision could be lost.

The OracleDataAdapter Safe Type Mapping feature prevents data loss when populating Oracle data for any of these types into a .NET DataSet. By setting the SafeMapping property appropriately, these types can be safely represented in the DataSet, as either of the following:

.NET byte[] in Oracle format

.NET String

By default, Safe Type Mapping is disabled.


Frank

patrick.van.dij...

Posts: 70
Registered: 04/26/05
Re: Any support for spatial and .NET?
Posted: Nov 24, 2005 3:16 AM   in response to: fjlee in response to: fjlee
Click to report abuse...   Click to reply to this thread Reply
Frank,

I work for a company called Spatial Eye (see http://www.spatial-eye.com/) and we have developed our own ODP.NET variant from scratch for having Object support (this until Oracle delivers Object support in ODP.NET).

But to start answering your question.
Do not use PathData or any other UI/Graphics related object to represent the Sdogeometry data, for several reasons:
1) Today we use Graphics class to render, but tomorow it might be Avalon (PathData is useless).
2) You might want to know what the Spatial Reference ID is...PathData doesn't know it.
3) Use an SdoGeometry type of object which holds all information in it's most native format, similar to what you have in JGeometry I guess, but I do not know the details of that implementation.

The most important things when using Oracle Spatial is performance, therefore we (in our ODP.NET solution) choose to convert the numbers from the elementInfo array to Int32 and the Ordinates to Double.We believe that for 99% of the cases a Double is accurate enough.


Converting the Ordinate array to a OracleDecimal (or .NET Decimal) first and later for rendering to a float might impact performance to much (although we have no hard figures here). We did had a look at the CoreLab Oracle Data Provider in the past, but it was really
slow when retrieving the SdoGeometry object using the generic OracleObject.

What we really would like to have is a way of handling the conversion from the internal SdoGeometry to whatever we like to have (and back when writing geometry) ourselves.
For that we have developed an OracleObjectFactory which can do those tricks.
So in our case we can use a simple conversion when rendering and another when we want
to do complex operations on the geometry outside the Oracle Server.

To summarize:
Use a JGeometry like structure (or class) with a Double[] for the Ordinates.
but please provide means of extracting other Oracle Objects using a factory mechanism,
so that the value can be converted to the appropriate .NET type.

Patrick

fjlee

Posts: 9
Registered: 01/10/01
Re: Any support for spatial and .NET?
Posted: Dec 1, 2005 6:16 AM   in response to: patrick.van.dij... in response to: patrick.van.dij...
Click to report abuse...   Click to reply to this thread Reply
Hi Patrick,

Thanks for your info and experience. I agree with you that the performance of ODP object-relational mapping is very important.

Frank
barnygumble

Posts: 14
Registered: 08/09/05
Re: Any support for spatial and .NET?
Posted: Feb 1, 2006 1:37 AM   in response to: sgreener in response to: sgreener
Click to report abuse...   Click to reply to this thread Reply
@sgreener

Your Solution looks very good. But I have some Problems to realize it.
1) Where can I find a OraCustomDynaset?
2) When I try to run a Query for e.g. sdo_gtype, then I get the error: "ORA-00904: Ungültiger Spaltenname" which means Wrong ColumnName.

My Select is:
"SELECT GST_SYMBOL.sdogeometry.sdo_gtype from GST_SYMBOL;"
GST_Symbol is the Table
sdogeometry is the Columname

Can you tell me whats going wrong?

thx

mfg Barny

patrick.van.dij...

Posts: 70
Registered: 04/26/05
Re: Any support for spatial and .NET?
Posted: Feb 1, 2006 1:49 AM   in response to: barnygumble in response to: barnygumble
Click to report abuse...   Click to reply to this thread Reply
Please read carefull, just must use aliases (as in the sample provided by sgreener)

The following should work:

select a.sdogeometry.sdo_gtype from gst_symbol a;

Patrick
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums