ArcSDE SDK Java quick practices 1

Source: Internet
Author: User
I. geometric objects

The definition of geometric objects in the ArcSDE SDK is distributed in many places and they have different purposes. Some of the geometric object types are organized in the com. ESRI. Sde. SDK. Geom package and include seshape and sdepoint in the com. ESRI. Sde. SDK. Client package.

The com. ESRI. Sde. SDK. Geom package organizes simple objects that comply with OGC specifications. The relationships between them are as follows:

Figure 1 class relationship diagram of COM. ESRI. Sde. SDK. Geom package

In the com. ESRI. Sde. SDK. Client package, the geometric objects in the ArcSDE client are organized.

· Segeometry

To construct a segeometry object, you also need a space reference object secoordref. For example, a point object should be constructed in the following way:

Secoordref Cr = new secoordref ();

Sepoint Pt = new sepoint (Cr, 116.39, 39.9 );

Here, a point object can be constructed through the X and Y coordinate values. Similarly, the line object and the surface object can be constructed through the set of sepoint points:

Secoordref Cr = new secoordref ();

Sepoint [] lspts = new sepoint [] {New sepoint (Cr, 0, 0 ),

New sepoint (Cr, 10, 0), new sepoint (Cr, 10, 10 )};

Selinestring ls = new selinestring (Cr, lspts );

System. Out. Print (LS. tostring ());

System. Out. println ("length" + ls. Length ());

System. Out. println ();

Sepoint [] [] pgpts = new sepoint [] [] {

{New sepoint (Cr, 0, 0), new sepoint (Cr, 100, 0 ),

New sepoint (Cr, 100,100), new sepoint (Cr, 0,100 ),

New sepoint (Cr, 0, 0 )},

{New sepoint (Cr, 20, 20), new sepoint (Cr, 40, 20 ),

New sepoint (Cr, 40, 40), new sepoint (Cr, 20, 40 ),

New sepoint (Cr, 20, 20 )}};

Sepolygon Pg = new sepolygon (Cr, pgpts );

System. Out. Print (pg. tostring ());

System. Out. println ("area" + PG. Area ());

The constructed object, its length and area are printed to verify the object's correctness: note that the polygon generated here is a polygon with holes.

Selinestring:

(Sepoint: 0 dx = 0.0, dy = 0.0)

(Sepoint: 1 dx = 10.0, dy = 0.0)

(Sepoint: 2 dx = 10.0, dy = 10.0)

Length 20.0

Sepolygon:

(Sepoint: 0 dx = 0.0, dy = 0.0)

(Sepoint: 1 dx = 100.0, dy = 0.0)

(Sepoint: 2 dx = 100.0, dy = 100.0)

(Sepoint: 3 dx = 0.0, dy = 100.0)

(Sepoint: 4 dx = 0.0, dy = 0.0)

(Sepoint: 5 dx = 20.0, dy = 20.0)

(Sepoint: 6 dx = 40.0, dy = 20.0)

(Sepoint: 7 dx = 40.0, dy = 40.0)

(Sepoint: 8 dx = 20.0, dy = 40.0)

(Sepoint: 9 dx = 20.0, dy = 20.0)

Area: 9600.0 square meters

· Seshape

Seshape is located in the com. ESRI. Sde. SDK. Client package. It can be considered as an ESRI shape object that exists on the ArcSDE client. Note that the ESRI shape object stored in the database not only contains the node coordinate information of the geometric object, but also the coordinate points, boundary range, length, area, and other information.

We can directly generate a seshape object from a segeometry object:

Secoordref Cr = new secoordref ();

Sepoint [] [] pgpts = new sepoint [] [] {

{New sepoint (Cr, 0, 0), new sepoint (Cr, 100, 0 ),

New sepoint (Cr, 100,100), new sepoint (Cr, 0,100 ),

New sepoint (Cr, 0, 0 )},

{New sepoint (Cr, 20, 20), new sepoint (Cr, 40, 20 ),

New sepoint (Cr, 40, 40), new sepoint (Cr, 20, 40 ),

New sepoint (Cr, 20, 20 )}};

Sepolygon Pg = new sepolygon (Cr, pgpts );

Seshape shape = new seshape ();

Shape. fromsegeometry (PG );

Or generate a seshape from the WKT string:

Seshape shape = new seshape (CR );

Shape. generatefromtext ("polygon (2, 2, 4, 4, 4, 2 ))");

Or obtain a seshape from the server:

Serow ROW = query. Fetch ();

While (row! = NULL ){

Try {

Seshape shape = row. getshape (1 );

} Catch (exception e ){

E. printstacktrace ();

}

Row = query. Fetch ();

}

You can view the seshape attributes. In addition to the node coordinate information, there are many other auxiliary information:

Figure 2 secondary information in seshape

· Spatial relationships and operations

The segeometry object and seshape object can both be used to determine the spatial relationship and perform spatial operations. Of course, most of the cases of spatial relationship judgment and operation occur after obtaining server data, therefore, seshape is more often used. Seshape is used to show how to determine whether two geometric objects meet various spatial relationships:

Try {

Seshape shape1 = new seshape ();

Shape1.generatefromtext ("linestring (0, 10, 10, 10 )");

Seshape shape2 = new seshape ();

Shape2.generatefromtext ("polygon (0, 10, 10, 0 ))");

System. Out. println ("contain:" + shape2.iscontaining (shape1 ));

System. Out. println ("Cross:" + shape2.iscrossing (shape1 ));

System. Out. println ("disjoint:" + shape2.isdisjoint (shape1 ));

System. Out. println ("overlap:" + shape2.isoverlapping (shape1 ));

System. Out. println ("Touch:" + shape2.istouching (shape1 ));

System. Out. println ("within:" + shape2.iswithin (shape1 ));

} Catch (exception ex ){

Ex. printstacktrace ();

}

For a geometric object, you can perform calculations such as buffering, closure, and annotation points:

Try {

Seshape shape = new seshape ();

Shape. generatefromtext ("polygon (10 10, 20 10, 20 20, 18 12, 10 10 ))");

Seshape buffer = shape. generatebuffer (2,100); // Buffer

System. Out. println (buffer. getarea ());

Seshape convexhull = shape. generateconvexhull (); // Closure

System. Out. println (convexhull. getarea ());

Sdepoint labelpoint = shape. generatelabelpoint (); // annotation point

System. Out. println ("X:" + labelpoint. getx () + ", Y:" + labelpoint. Gety ());

} Catch (exception ex ){

Ex. printstacktrace ();

}

The following operations can be performed on two geometric objects:

Try {

Seshape shape1 = new seshape ();

Shape1.generatefromtext ("polygon (10 10, 30 10, 30, 10 30 ))");

Seshape shape2 = new seshape ();

Shape2.generatefromtext ("polygon (0, 20, 20, 20, 0, 0 ))");

Seshape Union = shape1.union (shape2); // merge

System. Out. println (Union. getarea ());

Seshape [] intersect = shape1.intersect (shape2); // submit

Double area = 0;

For (INT I = 0, num = intersect. length; I

Area + = intersect [I]. getarea ();

}

System. Out. println (area );

Seshape XOR = shape1.symmetricaldifference (shape2); // merge and submit

System. Out. println (XOR. getarea ());

Seshape Difference = shape1.difference (shape2); // evaluate the difference

System. Out. println (difference. getarea ());

} Catch (exception ex ){

Ex. printstacktrace ();

}

In addition, for example, finding the shortest distance between two geometric objects:

Try {

Seshape shape1 = new seshape ();

Shape1.generatefromtext ("polygon (20, 30, 20, 30, 20, 20 ))");

Seshape shape2 = new seshape ();

Shape2.generatefromtext ("polygon (0, 10, 10, 10, 0, 0 ))");

Double distance = shape1.calculatedistance (shape2, true );

System. Out. println (distance );

} Catch (exception ex ){

Ex. printstacktrace ();

}

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.