ArcSDE SDK for Java Two development introduction, sample

Source: Internet
Author: User

In one job, we encountered the need for the Java backend to query the Oracle database spatial data used in ArcGIS, because the first contact with ArcGIS spatial data is that Oracle can use St_geometry field storage, as


However, the query will find that the St_geometry field will appear in the results of a number of sub-fields, for ArcGIS geography knowledge very little, do not know how to query a single coordinate how to get, some friends said that need to configure the listening file.

Anyway, at least refer to a Daniel's article, http://blog.csdn.net/linghe301/article/details/8058806, according to the ArcSDE for Java API, it can be used for the operation of additional pruning and checking.


For the introduction of ARCSDE for Java, please refer to the article, do not repeat the writing. The following example code, modified, added some comments, or good

Package Cn.sde.test;import Com.esri.sde.sdk.client.secolumndefinition;import Com.esri.sde.sdk.client.SeConnection ; Import Com.esri.sde.sdk.client.secoordinatereference;import Com.esri.sde.sdk.client.seexception;import Com.esri.sde.sdk.client.sefilter;import Com.esri.sde.sdk.client.seinstance;import Com.esri.sde.sdk.client.selayer;import Com.esri.sde.sdk.client.sequery;import Com.esri.sde.sdk.client.sequeryinfo;import Com.esri.sde.sdk.client.serelease;import Com.esri.sde.sdk.client.serow;import Com.esri.sde.sdk.client.seshape;import Com.esri.sde.sdk.client.seshapefilter;import Com.esri.sde.sdk.client.sesqlconstruct;import Com.esri.sde.sdk.client.setable;public class Arcsde_test3 {private static Seconnection conn = Null;private static String Server = "172.25.0.253"; SDE Server private static String instance = "5151"; SDE Port private static String database = "ORCL"; SDE database private static String username = "SDE"; SDE User name private static String password = "SDE"; SDE Password//Get ARCSDE connection privateStatic Seconnection Getconn () {if (conn = = null) {try {conn = new Seconnection (server, instance, database, username, PASSW ORD);} catch (Seexception ex) {ex.printstacktrace ();}} Return conn;} /** * ARCSDE management */public static void Getarcsdeinfo () {try {seinstance instance = new Seinstance (server, "5151"); Seinstance.seinstancestatus status = Instance.getstatus (); System.out.println ("Number of connections:" + status.getnumconnections ()); System.out.println ("Can connect:" + status.isaccepting ()); System.out.println ("------------------------------------------------"); seinstance.seinstanceconfiguration config = instance.getconfiguration (); SYSTEM.OUT.PRINTLN ("Maximum number of connections:" + config.getmaxconnections ()); System.out.println ("------------------------------------------------"); seinstance.seinstancestats[] stats = instance.getstats (); for (int i = 0; i < stats.length; i++) {System.out.println ("action Number: "+ stats[i].getoperationcount ());} System.out.println ("------------------------------------------------"); seinstance.seinstanceusers[] Users = instance.getusers (); for (int j = 0; J < Users.length; J + +) {System.out.println ("username:" + users[j].getusername ()); SYSTEM.OUT.PRINTLN ("System name:" + users[j].getsysname ()); SYSTEM.OUT.PRINTLN ("Server start time:" + users[j].getserverstarttime ()); SYSTEM.OUT.PRINTLN ("Server pid:" + users[j].getserverpid ()); System.out.println ("*****************************");} System.out.println ("------------------------------------------------"); SYSTEM.OUT.PRINTLN ("System name:" + instance.getservername ()); System.out.println ("------------------------------------------------"); System.out.println ("------------------------------------------------"); seinstance.seinstancetablelocks[] Tablelocks = Instance.gettablelocks (); for (int i = 0; i < tablelocks.length; i++) {Sy STEM.OUT.PRINTLN ("Table level lock Type:" + tablelocks[i].getlocktype ()); SYSTEM.OUT.PRINTLN ("Table level lock PID:" + tablelocks[i].getpid ()); SYSTEM.OUT.PRINTLN ("Table level Lock Registration ID:" + tablelocks[i].getregistrationid ()); System.out.println ("*****************************");} System.out.println ("------------------------------------------------");} catch (Seexception e) {e.printstacktrace ();}} /** * Spatial Condition query * The current problem is that the actual should return 2, but only returned a record, there is a friend who knows the solution please tell me, message kneeling thanks! */public static void Spatialquery_hz () {try {String tbname = "Ezgisdata.  DCQWG_HB ";//table name string[] cols = new string[7];//to query the array of fields cols[0] =" Jdname "; cols[1] =" Jdcode "; cols[2] =" Sqname "; cols[3] = "Sqcode"; cols[4] = "wgname"; cols[5] = "Wgcode"; cols[6] = "TYPE"; Seconnection conn = Getconn (); Selayer layer = new Selayer (conn, tbname, "shape");//shape is the spatial data field in the table to be queried secoordinatereference CR = Layer.getcoordref (); Sefilter[] Filters = new SEFILTER[1]; Seshape shape = new Seshape (CR);d ouble x = 507638.3125000;//x coordinate double y = 303547.9687500;//y-coordinate double xs = 0.000000001;do uble x1 = x-xs;double y1 = y + xs;double x2 = x + xs;double y2 = y + xs;double x3 = x + xs;double y3 = y-xs;double x4 = X-xs;double Y4 = Y-xs; String polygonstr = "POLYGON ((" + double.tostring (x1) + "" + double.tostring (y1);p olygonstr = Polygonstr + "," + Double. Tostring(x2) + "" + double.tostring (y2);p olygonstr = Polygonstr + "," + double.tostring (x3) + "" + double.tostring (y3);p Olygonst  r = polygonstr + "," + double.tostring (x4) + "" + double.tostring (y4);p olygonstr = Polygonstr + "," + double.tostring (x1) + "" + double.tostring (y1);p olygonstr = polygonstr + ")"; Shape.generatefromtext (POLYGONSTR);//Set query parameters according to polygon query//SD Epoint pt = new Sdepoint (507638.3125000,303547.9687500);//x,y//shape.generatepoint (1, new sdepoint[] {pt}); Sefilter filter = new Seshapefilter (Tbname, Layer.getspatialcolumn (), shape, seshapefilter.method_ai);//Set Filter filters[0 ] = filter; Sesqlconstruct sqlcons = new Sesqlconstruct (tbname); Sequery query = new Sequery (conn, cols, sqlcons); Query.preparequery (); Query.setspatialconstraints (Sequery.se_ OPTIMIZE, False, filters); Query.execute (); Serow row = Query.fetch ()//function similar to database cursor int reccount = 0;while (row! = null) {RecCount = RecCount + 1; String info = integer.tostring (reccount); for (int i = 0; i < cols.length; i++) {//fields and resultsAlso output info = info + ":" + cols[i] + ":" + row.getobject (i). toString ();} SYSTEM.OUT.PRINTLN (info); row = Query.fetch ();}} catch (Exception ex) {ex.printstacktrace ();}} /** * Attribute condition query */public static void Attributequery () {try {String tbname = "Ezgisdata. Dcqwg_py "; string[] cols = new String[4];cols[0] = "NEWSQMC"; cols[1] = "NEWSQBM"; cols[2] = "NEWWGMC"; cols[3] = "NEWWGBM"; Seconnection conn = Getconn (); Sesqlconstruct sqlcons = new Sesqlconstruct (tbname); Sqlcons.setwhere ("Jdname= ' Li Ping");//set conditions, similar to SQL statements sequery query = New Sequery (conn, cols, sqlcons); Query.preparequery (cols, sqlcons); Query.execute (); Serow row = Query.fetch (); int reccount = 0;while (row! = null) {RecCount = RecCount + 1; System.out.println (integer.tostring (RecCount) + ":" + row.getobject (0). ToString () + ":" + row.getobject (1). ToString () + ":" + row.getobject (2). ToString () + ":" + row.getobject (3). ToString ()); row = Query.fetch ();}} catch (Exception ex) {ex.printstacktrace ();}} /** * Normal query */public static void Commonquery (){try {seconnection conn = Getconn (); setable table = new setable (conn, "Ezgisdata. Dcqwg_py "); secolumndefinition[] TableDef = Table.describe (); string[] cols = new String[tabledef.length];for (int j = 0; J < Cols.length; J + +) {Cols[j] = Tabledef[j].getname ();} Sesqlconstruct sqlcons = new Sesqlconstruct ("Ezgisdata. Dcqwg_py "); Sequery query = new Sequery (conn, cols, sqlcons); Sequeryinfo queryinfo = new Sequeryinfo (); Queryinfo.setquerytype (Sequeryinfo.se_querytype_attribute_first); Queryinfo.setcolumns (cols); queryinfo.setconstruct (sqlcons); Query.preparequeryinfo (QueryInfo); Query.execute (); Serow row = Query.fetch (); while (row! = null) {System.out.println (row.getobject (0). toString () + ":" + row.getobject (1). t  Ostring () + ":" + row.getobject (3). ToString () + ":" + row.getobject (4). ToString () + ":" + row.getobject (5). ToString () + ":" + row.getobject (6). ToString () + ":" + row.getobject (7). ToString () + ":" + row.getobject (8). ToString ()); row = Query.fetch ();}} catch (Exception ex) {EX.PRintstacktrace ();}} /** * Get ArcSDE version information */public static void GetVersion () {Seconnection conn = Getconn (); Serelease release = Conn.getrelease (); System.out.println (Release.getbugfix ()); System.out.println (Release.getdesc ()); System.out.println (Release.getrelease ()); System.out.println (Release.getmajor ()); System.out.println (Release.getminor ());} public static void Main (string[] args) {//Getarcsdeinfo ();//GetVersion ();//Commonquery ();//Attributequery (); Spatialquery_hz ();//Spatial Query}}
Results:

------------------------------------------------
1:jdname: East Flower Market: Jdcode:13:sqname: Faithful Community: Sqcode:1303:wgname: Faithful Community No. 3rd grid: WGCODE:13033-0152:TYPE:SG





ArcSDE SDK for Java Two development introduction, sample

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.