﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Rising Sun -随笔分类-cpp</title><link>http://www.blogjava.net/brock/category/54071.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 30 May 2014 06:07:50 GMT</lastBuildDate><pubDate>Fri, 30 May 2014 06:07:50 GMT</pubDate><ttl>60</ttl><item><title>第一个C++类 geodatabase 转gml</title><link>http://www.blogjava.net/brock/archive/2014/01/02/408368.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 02 Jan 2014 02:19:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/01/02/408368.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/408368.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/01/02/408368.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/408368.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/408368.html</trackback:ping><description><![CDATA[<div>头文件<br />#ifndef CLASS_GEOMETRYTOSTRING</div><div>#define CLASS_GEOMETRYTOSTRING</div><div>&nbsp;</div><div>#include &lt;iostream&gt;</div><div>#include &lt;FileGDBAPI.h&gt;</div><div></div><div>using namespace std;</div><div></div><div>class GeometryToString</div><div></div><div>{</div><div>public:</div><div><span style="white-space:pre">	</span>static &nbsp;bool getGeometryStr( FileGDBAPI::ShapeBuffer &amp;geometry,string srid,string &amp;geometrystr);&nbsp;</div><div>private:</div><div><span style="white-space:pre">	</span>static void getPointGML(FileGDBAPI::PointShapeBuffer *&amp;pbuffer,string srid,string dimension, string &amp;xml);</div><div><span style="white-space:pre">	</span>static void getLineGML(FileGDBAPI::MultiPartShapeBuffer *&amp;lineGeometry,string srid,string dimension, string &amp;xml);</div><div><span style="white-space:pre">	</span>static void getMultipointGML(FileGDBAPI::MultiPointShapeBuffer *&amp;multipointGeometry,string srid,string dimension, string &amp;xml);</div><div><span style="white-space:pre">	</span>static void getPolygonGML(FileGDBAPI::MultiPartShapeBuffer *&amp;polygonGeometry,string srid,string dimension, string &amp;xml);</div><div>};</div><div></div><div>#endif<br />--------------------------------<br /><div>#include &lt;jni.h&gt;</div><div>#include &lt;stdio.h&gt;</div><div>#include &lt;iostream&gt;</div><div></div><div>#include &lt;string&gt;</div><div>#include &lt;fstream&gt;</div><div>#include &lt;time.h&gt;</div><div>#include &lt;sstream&gt;&nbsp;</div><div>#include &lt;FileGDBAPI.h&gt;</div><div>#include "GeometryToString.h"</div><div>using namespace FileGDBAPI;</div><div>using namespace std;</div><div></div><div>/**</div><div>ShapeBuffer geometry format to gml</div><div>*/</div><div>bool GeometryToString::getGeometryStr( ShapeBuffer &amp;geometry,string srid,string &amp;geometrystr) &nbsp; &nbsp;&nbsp;</div><div>{</div><div></div><div><span style="white-space:pre">	</span>ShapeType pType;</div><div><span style="white-space:pre">	</span>string dimension("2");</div><div></div><div><span style="white-space:pre">	</span>try{</div><div><span style="white-space:pre">		</span>geometry.GetShapeType(pType);</div><div></div><div><span style="white-space:pre">		</span>if(pType==shapeNull){</div><div><span style="white-space:pre">			</span>return false;</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>if(geometry.HasMs(pType) || geometry.HasZs(pType)){</div><div><span style="white-space:pre">			</span>dimension.assign("3");</div><div><span style="white-space:pre">		</span>}</div><div></div><div></div><div><span style="white-space:pre">		</span>//点</div><div><span style="white-space:pre">		</span>if(pType==shapePoint){</div><div><span style="white-space:pre">			</span>PointShapeBuffer *pPoint = static_cast&lt;PointShapeBuffer*&gt;(&amp;geometry);</div><div><span style="white-space:pre">			</span>getPointGML(pPoint, srid, dimension, geometrystr);</div><div></div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>//复杂点 shapeMultipoint &nbsp; &nbsp; &nbsp; &nbsp; = &nbsp;8, shapeMultipointM &nbsp; &nbsp; &nbsp; &nbsp;= 28, &nbsp;shapeMultipointZM &nbsp; &nbsp; &nbsp; = 18, shapeMultipointZ &nbsp; &nbsp; &nbsp; &nbsp;= 20,</div><div><span style="white-space:pre">		</span>else if(pType==shapeMultipoint||pType==shapeMultipointZ){</div><div><span style="white-space:pre">			</span>MultiPointShapeBuffer *pPoint = static_cast&lt;MultiPointShapeBuffer*&gt;(&amp;geometry);</div><div><span style="white-space:pre">			</span>getMultipointGML(pPoint, srid, dimension, geometrystr);</div><div></div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>//线</div><div><span style="white-space:pre">		</span>else if(pType==shapePolyline||pType==shapePolylineZ){</div><div></div><div><span style="white-space:pre">			</span>MultiPartShapeBuffer *pPoint = static_cast&lt;MultiPartShapeBuffer*&gt;(&amp;geometry);</div><div><span style="white-space:pre">			</span>getLineGML(pPoint, srid, dimension, geometrystr);</div><div></div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>//面 shapePolygon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= &nbsp;5, shapePolygonM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 25, &nbsp;shapePolygonZM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 15, &nbsp;shapePolygonZ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 19,</div><div><span style="white-space:pre">		</span>else if(pType==shapePolygon||pType==shapePolygonZ){</div><div></div><div><span style="white-space:pre">			</span>MultiPartShapeBuffer *pPoint = static_cast&lt;MultiPartShapeBuffer*&gt;(&amp;geometry);</div><div><span style="white-space:pre">			</span>getPolygonGML(pPoint, srid, dimension, geometrystr);</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>//geometrystr = xml;</div><div><span style="white-space:pre">	</span>}catch(exception&amp; e){</div><div><span style="white-space:pre">		</span>cout &lt;&lt;"格式化gml出错"&lt;&lt; e.what() &lt;&lt; '\n';</div><div><span style="white-space:pre">		</span>return false;</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>return true;</div><div>}</div><div></div><div>/**</div><div>&lt;gml:Polygon srsName="SDO:4269" xmlns:gml="http://www.opengis.net/gml"&gt;</div><div>&lt;gml:exterior&gt;</div><div>&lt;gml:LinearRing&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;-73.2580598287651 42.7460586400617 -73.0196951738303 42.740396678634 -72.9229974292253 42.7373644761786 -72.4557700038866 42.7258525290856 -72.4621713056891 42.7468405310805 -72.4793225257782 42.7615879021406 -72.507269529053 42.768732690401 -72.513068008801 42.7892594013537 -72.5389169708409 42.8077338159122 -72.5534284639708 42.8606431711071 -72.5248100213574 42.912614176111 -72.5202170578447 42.951672527189 -72.5042636319544 42.9655846501007 -72.4733411974969 42.9761435837694 -72.4571590376321 42.9996036974295 -72.461752087004 43.0465044640799 -72.4434642578885 43.0790393128302 -72.4376049020671 43.1162700005077 -72.4523985528512 43.1560221784821 -72.4355986440692 43.2322535514026 -72.4024188454006 43.3073827061476 -72.4102315830492 43.3234041461304 -72.3976280543775 43.3510068532968 -72.4121395531362 43.3771255999364 -72.3962478080998 43.4101565518933 -72.3825156946812 43.4846296935806 -72.3949977682121 43.5175538931663 -72.3734983899535 43.5723746289273 -72.3330851941569 43.597364792188 -72.3040399378543 43.6985301192074 -72.2600555952028 43.7353001230665 -72.219122921336 43.7506925284353 -72.2060918209679 43.7646350589214 -72.1848363730122 43.80169046066 -72.1700895247441 43.8789176964692 -72.1216496397887 43.9092173247051 -72.1132040793556 43.9391659598858 -72.0917117306645 43.9579911279466 -72.1128078470402 43.9765149671878 -72.109908766997 43.9892291134735 -72.0852043813773 44.0089239861752 -72.0769190441221 44.0320405986229 -72.0347283650035 44.0833740182692 -72.0324473746587 44.0960996192242 -72.0495148341973 44.1004520944913 -72.034919852375 44.1207459288225 -72.0447245537617 44.1564355666161 -72.0592822460624 44.1821766291117 -72.0443903804218 44.2343798441307 -72.0595660047421 44.2614940911533 -72.0354953753776 44.2994343131499 -71.9944335108703 44.327548202346 -71.9389056579791 44.3257860034125 -71.9283617527138 44.3361121851129 -71.8348159803514 44.3441994129005 -71.821197308355 44.3503600453548 -71.7977291908463 44.3841728130012 -71.7665702593917 44.3982488046659 -71.6768843632127 44.4213427403399 -71.6563990024127 44.4401373612433 -71.6477091613881 44.4691741459765 -71.6365547217831 44.4767309013869 -71.6142227691161 44.4745070427354 -71.5866189807601 44.4945375694191 -71.5752435447921 44.5258056891543 -71.5914413886211 44.5388744007984 -71.5922884113102 44.5512031068491 -71.5367908177936 44.578931263059 -71.554102635183 44.5965889130363 -71.5680271516494 44.6374468081651 -71.588749347522 44.6505994869911 -71.6076787297883 44.6778622938611 -71.6311328527304 44.741710760694 -71.583501209059 44.779196995866 -71.5751009123659 44.8160197976273 -71.5063649605901 44.8996711859762 -71.5169776077168 44.9436961331566 -71.5409270967342 44.9765632062274 -71.5053723006288 45.0133517163227 -71.9018687560566 45.0073398737601 -72.547231170846 45.0053701041526 -73.1885457846918 45.0084861445147 -73.3447234868808 45.0061387945908 -73.3507583871194 44.9819729513452 -73.336414678892 44.9326039308501 -73.3823067594393 44.847933618761 -73.3690541280725 44.8191179021752 -73.3267863194035 44.7992935709543 -73.3731585750219 44.7242364367472 -73.3581509561493 44.6803685644813 -73.3730971364166 44.661276356252 -73.3701366913554 44.6343490646186 -73.3818251037205 44.619807725515 -73.3712960298211 44.5791669569445 -73.3478119840265 44.5539715457203 -73.3344524939974 44.5443282463014 -73.2933197444992 44.4328535783628 -73.2999951630005 44.4055331645411 -73.329788093029 44.3673904680867 -73.3053256664728 44.2601422576288 -73.3773326255291 44.2012475171298 -73.3820623364064 44.1721076120789 -73.4078648304615 44.1362270392698 -73.408756830709 44.1066103535608 -73.4352152780239 44.0638978024284 -73.4360007112789 44.0456791904392 -73.4082513023357 44.0182219013789 -73.4174061301201 43.9881969457531 -73.4053345287368 43.9148075869024 -73.3751207851313 43.8859769501208 -73.3847399017653 43.8045079717314 -73.35899716813 43.7784275686935 -73.3566696765928 43.7565583405993 -73.3709893845573 43.7142811167279 -73.4229598542952 43.6321147289768 -73.4183198417113 43.5824793859982 -73.38811421923 43.569143658301 -73.3636855615672 43.6149988679746 -73.303534516911 43.6247148128503 -73.2941043006646 43.6196528756939 -73.2817362682322 43.593187249577 -73.2914024969012 43.5750335705379 -73.2599837938072 43.5593823395161 -73.2383913589494 43.5128328494146 -73.2500714436228 43.3108539907423 -73.2760052890117 42.9402941192892 -73.2795831999318 42.8371033274803 -73.2961697572314 42.8035493647592 -73.2692753169001 42.7474814329983 -73.2580598287651 42.7460586400617 &lt;/gml:posList&gt;</div><div>&lt;/gml:LinearRing&gt;</div><div>&lt;/gml:exterior&gt;</div><div>&lt;/gml:Polygon&gt;</div><div>-----------------------------------------</div><div>&lt;gml:MultiSurface srsName="SDO:4269" xmlns:gml="http://www.opengis.net/gml"&gt;</div><div>&lt;gml:surfaceMember&gt;</div><div>&lt;gml:Polygon&gt;</div><div>&lt;gml:exterior&gt;</div><div>&lt;gml:LinearRing&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;-71.7901942031213 41.6013068793251 -71.8027434308056 41.415829054006 -71.8459956537022 41.403854541649 -71.8368696812943 41.3419614666217 -71.8477722040922 41.3253484832966 -71.866678442895 41.3227696452717 -71.7222643227053 41.327264312184 -71.4898880400564 41.3920853196253 -71.427318519639 41.4866893796324 -71.4192468515382 41.6522122329241 -71.3690125475301 41.7032911019032 -71.3935805976545 41.7611558353254 -71.3673874451962 41.7413502009834 -71.2840016520154 41.6795489704365 -71.2289761591777 41.7076939683675 -71.2666285816006 41.7497430522049 -71.3193277902704 41.7721958646079 -71.33979862314 41.784425562696 -71.3454831662469 41.8131613833438 -71.3345427095385 41.8579036075386 -71.3424931202155 41.875782891498 -71.3330859502879 41.8960311596525 -71.3839531547034 41.8884397544728 -71.3824052822434 41.9792630768654 -71.3786442228911 42.0137133195164 -71.4974303691298 42.0092535031424 -71.7978316087618 42.0042748046853 -71.7882488621949 41.721603395324 -71.7926052182918 41.6417579304639 -71.7901942031213 41.6013068793251 &lt;/gml:posList&gt;</div><div>&lt;/gml:LinearRing&gt;</div><div>&lt;/gml:exterior&gt;</div><div>&lt;/gml:Polygon&gt;</div><div>&lt;/gml:surfaceMember&gt;</div><div>&lt;gml:surfaceMember&gt;</div><div>&lt;gml:Polygon&gt;</div><div>&lt;gml:exterior&gt;</div><div>&lt;gml:LinearRing&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;-71.1988086806703 41.6785003452844 -71.1999371652607 41.4633184834308 -71.1171327154704 41.4930619563069 -71.1412126344661 41.6552730544526 -71.1988086806703 41.6785003452844 &lt;/gml:posList&gt;</div><div>&lt;/gml:LinearRing&gt;</div><div>&lt;/gml:exterior&gt;</div><div>&lt;/gml:Polygon&gt;</div><div>&lt;/gml:surfaceMember&gt;</div><div>&lt;gml:surfaceMember&gt;</div><div>&lt;gml:Polygon&gt;</div><div>&lt;gml:exterior&gt;</div><div>&lt;gml:LinearRing&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;-71.2691694549114 41.6212683171835 -71.3495250332551 41.445857741455 -71.288007152861 41.4836193369167 -71.2386732340455 41.4748497781273 -71.2194468005559 41.6356423127122 -71.2691694549114 41.6212683171835 &lt;/gml:posList&gt;</div><div>&lt;/gml:LinearRing&gt;</div><div>&lt;/gml:exterior&gt;</div><div>&lt;/gml:Polygon&gt;</div><div>&lt;/gml:surfaceMember&gt;</div><div>&lt;/gml:MultiSurface&gt;</div><div>*/</div><div>void GeometryToString::getPolygonGML(FileGDBAPI::MultiPartShapeBuffer *&amp;polygonGeometry,string srid,string dimension, string &amp;xml){</div><div></div><div><span style="white-space:pre">	</span>int numPts;</div><div><span style="white-space:pre">	</span>polygonGeometry-&gt;GetNumPoints(numPts);</div><div></div><div><span style="white-space:pre">	</span>int numParts;</div><div><span style="white-space:pre">	</span>polygonGeometry-&gt;GetNumParts(numParts);</div><div></div><div></div><div><span style="white-space:pre">	</span>int* parts;</div><div><span style="white-space:pre">	</span>polygonGeometry-&gt;GetParts(parts);</div><div></div><div><span style="white-space:pre">	</span>Point* points;</div><div><span style="white-space:pre">	</span>polygonGeometry-&gt;GetPoints(points);</div><div></div><div></div><div></div><div><span style="white-space:pre">	</span>string gmlSub("");</div><div></div><div><span style="white-space:pre">	</span>if(numParts==1){</div><div></div><div><span style="white-space:pre">		</span>xml= "&lt;gml:Polygon srsName=\"SDO:"+srid+"\" xmlns:gml=\"http://www.opengis.net/gml\"&gt; \</div><div><span style="white-space:pre">												</span>&lt;gml:exterior&gt; \</div><div><span style="white-space:pre">												</span>&lt;gml:LinearRing&gt; \</div><div><span style="white-space:pre">												</span>&lt;gml:posList srsDimension=\""+dimension+"\"&gt;";</div><div></div><div><span style="white-space:pre">		</span>for (int i = 0; i &lt; numPts; i++)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>char buffer[32];</div><div><span style="white-space:pre">			</span>sprintf(buffer, "%1.14g", points[i].x);</div><div><span style="white-space:pre">			</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">			</span>sprintf(buffer, "%1.14g", points[i].y);</div><div><span style="white-space:pre">			</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">		</span>}<span style="white-space:pre">				</span> &nbsp;</div><div><span style="white-space:pre">		</span>xml.append(gmlSub);</div><div><span style="white-space:pre">		</span>xml.append("&lt;/gml:posList&gt;&lt;/gml:LinearRing&gt;\</div><div><span style="white-space:pre">				</span> &nbsp; &lt;/gml:exterior&gt;\</div><div><span style="white-space:pre">				</span> &nbsp; &lt;/gml:Polygon&gt;");</div><div></div><div><span style="white-space:pre">		</span>return;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>if(numParts&gt;1){</div><div><span style="white-space:pre">		</span>xml="&lt;gml:MultiSurface srsName=\"SDO:"+srid+"\" xmlns:gml=\"http://www.opengis.net/gml\"&gt;";</div><div></div><div><span style="white-space:pre">		</span>for(int i=0;i&lt;numParts;i++){</div><div></div><div></div><div><span style="white-space:pre">			</span>gmlSub.append("&lt;gml:surfaceMember&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:Polygon&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:exterior&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:LinearRing&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:posList srsDimension=\"").append(dimension).append("\"&gt;");</div><div></div><div><span style="white-space:pre">			</span>int gt=0;</div><div><span style="white-space:pre">			</span>if( i==(numParts-1)){</div><div><span style="white-space:pre">				</span>gt=numPts;</div><div><span style="white-space:pre">			</span>}else{</div><div><span style="white-space:pre">				</span>gt=parts[i+1];</div><div><span style="white-space:pre">			</span>}</div><div></div><div><span style="white-space:pre">			</span>for (int j= parts[i]; j &lt; gt; j++){</div><div></div><div><span style="white-space:pre">				</span>char buffer[32];</div><div><span style="white-space:pre">				</span>sprintf(buffer, "%1.14g", points[j].x);</div><div><span style="white-space:pre">				</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">				</span>sprintf(buffer, "%1.14g", points[j].y);</div><div><span style="white-space:pre">				</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">			</span>}</div><div></div><div><span style="white-space:pre">			</span>gmlSub.append("&lt;/gml:posList&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:LinearRing&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:exterior&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:Polygon&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:surfaceMember&gt;");</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>xml.append(gmlSub);</div><div></div><div><span style="white-space:pre">		</span>xml.append("&lt;/gml:MultiSurface&gt;");</div><div><span style="white-space:pre">		</span>return;</div><div><span style="white-space:pre">	</span>}</div><div></div><div>}</div><div></div><div>/**</div><div>&lt;gml:MultiPoint srsName="SDO:2230" xmlns:gml="http://www.opengis.net/gml"&gt;</div><div>&lt;gml:pointMember&gt;</div><div>&lt;gml:Point&gt;</div><div>&lt;gml:posList srsDimension="3"&gt;6301153.87493073 1913012.75794829 435.0 &lt;/gml:posList&gt;</div><div>&lt;/gml:Point&gt;</div><div>&lt;/gml:pointMember&gt;</div><div>&lt;gml:pointMember&gt;</div><div>&lt;gml:Point&gt;</div><div>&lt;gml:posList srsDimension="3"&gt;6301172.62522131 1913331.50796697 424.0 &lt;/gml:posList&gt;</div><div>&lt;/gml:Point&gt;</div><div>&lt;/gml:pointMember&gt;</div><div>&lt;/gml:MultiPoint&gt;</div><div>*/</div><div>void GeometryToString::getMultipointGML(FileGDBAPI::MultiPointShapeBuffer *&amp;multipointGeometry,string srid,string dimension, string &amp;xml){</div><div></div><div><span style="white-space:pre">	</span>int numPts;</div><div><span style="white-space:pre">	</span>multipointGeometry-&gt;GetNumPoints(numPts);</div><div><span style="white-space:pre">	</span>wcout &lt;&lt; "Multipoint test:" &lt;&lt; endl;</div><div><span style="white-space:pre">	</span>wcout &lt;&lt; "Points: " &lt;&lt; numPts &lt;&lt; endl;</div><div></div><div><span style="white-space:pre">	</span>Point* points;</div><div><span style="white-space:pre">	</span>multipointGeometry-&gt;GetPoints(points);</div><div></div><div><span style="white-space:pre">	</span>double* zArray;</div><div><span style="white-space:pre">	</span>multipointGeometry-&gt;GetZs(zArray);</div><div></div><div><span style="white-space:pre">	</span>xml= "&lt;gml:MultiPoint srsName=\"SDO:"+srid+"\" xmlns:gml=\"http://www.opengis.net/gml\"&gt; ";</div><div><span style="white-space:pre">	</span>string gmlSub("");</div><div><span style="white-space:pre">	</span>for (int i = 0; i &lt; numPts; i++)</div><div><span style="white-space:pre">	</span>{</div><div></div><div><span style="white-space:pre">		</span>gmlSub.append("&lt;gml:pointMember&gt;&lt;gml:Point&gt;&lt;gml:posList srsDimension=\""+dimension+"\"&gt;");</div><div><span style="white-space:pre">		</span>char buffer[32];</div><div><span style="white-space:pre">		</span>sprintf(buffer, "%1.14g", points[i].x);</div><div><span style="white-space:pre">		</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">		</span>sprintf(buffer, "%1.14g", points[i].y);</div><div><span style="white-space:pre">		</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">		</span>sprintf(buffer, "%1.14g", zArray[i]);</div><div><span style="white-space:pre">		</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">		</span>gmlSub.append("&lt;/gml:posList&gt;&lt;/gml:Point&gt;&lt;/gml:pointMember&gt;");</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>xml.append(gmlSub);</div><div><span style="white-space:pre">	</span>xml.append("&lt;/gml:MultiPoint&gt;");</div><div>}</div><div>/**</div><div>&lt;gml:Curve srsName="SDO:4269" xmlns:gml="http://www.opengis.net/gml"&gt;</div><div>&lt;gml:segments&gt;</div><div>&lt;gml:LineStringSegment&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;-91.3082592401631 40.0073363232732 -91.3055891069314 39.995346341049 -91.3139124547158 39.9690362798168 -91.3254189367963 39.9469572142013 -91.3246098997585 39.9350861975012 -91.32260281264 39.9251371873939 -91.3238158572038 39.896847138931 -91.3220157795743 39.8891571322064 -91.3241598689896 39.8853761196319 -91.3383584637069 39.873997056967 -91.3394875098243 39.8690760451917 -91.3354593387828 39.8630950480564 -91.3031399738825 39.8280070993682 -91.3022619338156 39.8090860744066 -91.2985697775187 39.7987370721841 -91.3005688605598 39.7949870596141 -91.3073361425165 39.7886050259611 -91.3117993281738 39.783596002295 -91.3119823326406 39.7676969773468 -91.3108232836762 39.7648359772821 -91.3049330369361 39.7602849923819 -91.2990957929273 39.7579610108158 -91.1947826970924 39.7164273102698 &lt;/gml:posList&gt;</div><div>&lt;/gml:LineStringSegment&gt;</div><div>&lt;/gml:segments&gt;</div><div>&lt;/gml:Curve&gt;</div><div></div><div></div><div></div><div>&lt;gml:MultiCurve srsName="SDO:4269" xmlns:gml="http://www.opengis.net/gml"&gt;</div><div>&lt;gml:curveMember&gt;</div><div>&lt;gml:Curve&gt;</div><div>&lt;gml:segments&gt;</div><div>&lt;gml:LineStringSegment&gt;</div><div>&lt;gml:posList srsDimension="2"&gt; sssss&lt;/gml:posList&gt;</div><div>&lt;/gml:LineStringSegment&gt;</div><div>&lt;/gml:segments&gt;</div><div>&lt;/gml:Curve&gt;</div><div>&lt;/gml:curveMember&gt;</div><div>&lt;gml:curveMember&gt;</div><div>&lt;gml:Curve&gt;</div><div>&lt;gml:segments&gt;</div><div>&lt;gml:LineStringSegment&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;sssss &lt;/gml:posList&gt;</div><div>&lt;/gml:LineStringSegment&gt;</div><div>&lt;/gml:segments&gt;</div><div>&lt;/gml:Curve&gt;</div><div>&lt;/gml:curveMember&gt;</div><div>&lt;/gml:MultiCurve&gt;</div><div></div><div>*/</div><div>void GeometryToString::getLineGML(MultiPartShapeBuffer *&amp;lineGeometry,string srid,string dimension, string &amp;xml)</div><div>{</div><div></div><div></div><div><span style="white-space:pre">	</span>int numPts,numParts;</div><div><span style="white-space:pre">	</span>lineGeometry-&gt;GetNumPoints(numPts);</div><div></div><div><span style="white-space:pre">	</span>lineGeometry-&gt;GetNumParts(numParts);</div><div></div><div></div><div><span style="white-space:pre">	</span>int* parts;</div><div><span style="white-space:pre">	</span>lineGeometry-&gt;GetParts(parts);</div><div></div><div><span style="white-space:pre">	</span>Point* points;</div><div><span style="white-space:pre">	</span>lineGeometry-&gt;GetPoints(points);</div><div></div><div></div><div><span style="white-space:pre">	</span>string gmlSub("");</div><div></div><div><span style="white-space:pre">	</span>if(numParts==1){</div><div></div><div><span style="white-space:pre">		</span>xml= "&lt;gml:Curve srsName=\"SDO:"+srid+"\" xmlns:gml=\"http://www.opengis.net/gml\"&gt; \</div><div><span style="white-space:pre">											</span> &nbsp;&lt;gml:segments&gt; \</div><div><span style="white-space:pre">											</span> &nbsp;&lt;gml:LineStringSegment&gt; \</div><div><span style="white-space:pre">											</span> &nbsp;&lt;gml:posList srsDimension=\""+dimension+"\"&gt;";</div><div></div><div><span style="white-space:pre">		</span>for (int i = 0; i &lt; numPts; i++)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>char buffer[32];</div><div><span style="white-space:pre">			</span>sprintf(buffer, "%1.14g", points[i].x);</div><div><span style="white-space:pre">			</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">			</span>sprintf(buffer, "%1.14g", points[i].y);</div><div><span style="white-space:pre">			</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">		</span>}<span style="white-space:pre">				</span> &nbsp;</div><div><span style="white-space:pre">		</span>xml.append(gmlSub);</div><div><span style="white-space:pre">		</span>xml.append("&lt;/gml:posList&gt; \</div><div><span style="white-space:pre">				</span> &nbsp; &lt;/gml:LineStringSegment&gt;\</div><div><span style="white-space:pre">				</span> &nbsp; &lt;/gml:segments&gt; \</div><div><span style="white-space:pre">				</span> &nbsp; &lt;/gml:Curve&gt;");</div><div></div><div><span style="white-space:pre">		</span>return;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>if(numParts&gt;1){</div><div><span style="white-space:pre">		</span>xml="&lt;gml:MultiCurve srsName=\"SDO:"+srid+"\" xmlns:gml=\"http://www.opengis.net/gml\"&gt;";</div><div></div><div><span style="white-space:pre">		</span>for(int i=0;i&lt;numParts;i++){</div><div></div><div><span style="white-space:pre">			</span>gmlSub.append("&lt;gml:curveMember&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:Curve&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:segments&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:LineStringSegment&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;gml:posList srsDimension=\"").append(dimension).append("\"&gt;");</div><div></div><div><span style="white-space:pre">			</span>int gt=0;</div><div><span style="white-space:pre">			</span>if( i==(numParts-1)){</div><div><span style="white-space:pre">				</span>gt=numPts;</div><div><span style="white-space:pre">			</span>}else{</div><div><span style="white-space:pre">				</span>gt=parts[i+1];</div><div><span style="white-space:pre">			</span>}</div><div></div><div><span style="white-space:pre">			</span>for (int j= parts[i]; j &lt; gt; j++){</div><div></div><div><span style="white-space:pre">				</span>char buffer[32];</div><div><span style="white-space:pre">				</span>sprintf(buffer, "%1.14g", points[j].x);</div><div><span style="white-space:pre">				</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">				</span>sprintf(buffer, "%1.14g", points[j].y);</div><div><span style="white-space:pre">				</span>gmlSub.append(buffer).append(" ");</div><div><span style="white-space:pre">			</span>}</div><div></div><div><span style="white-space:pre">			</span>gmlSub.append("&lt;/gml:posList&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:LineStringSegment&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:segments&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:Curve&gt;\</div><div><span style="white-space:pre">						</span> &nbsp;&lt;/gml:curveMember&gt;");</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>xml.append(gmlSub);</div><div></div><div><span style="white-space:pre">		</span>xml.append("&lt;/gml:MultiCurve&gt;");</div><div><span style="white-space:pre">		</span>return;</div><div><span style="white-space:pre">	</span>}</div><div></div><div>}</div><div></div><div></div><div>/*</div><div>&lt;gml:Point srsName="SDO:4269" xmlns:gml="http://www.opengis.net/gml"&gt;</div><div>&lt;gml:posList srsDimension="2"&gt;-88.0261499418109 44.4722440557492 &lt;/gml:posList&gt;</div><div>&lt;/gml:Point&gt;</div><div>*/</div><div>void GeometryToString::getPointGML( PointShapeBuffer *&amp;pbuffer,string srid,string dimension, string &amp;xml)</div><div>{</div><div></div><div><span style="white-space:pre">	</span>xml= "&lt;gml:Point srsName=\"SDO:"+srid+"\" xmlns:gml=\"http://www.opengis.net/gml\"&gt;&lt;gml:posList srsDimension=\""+dimension+"\"&gt;";</div><div></div><div><span style="white-space:pre">	</span>Point* points;</div><div><span style="white-space:pre">	</span>pbuffer-&gt;GetPoint(points);</div><div><span style="white-space:pre">	</span>char buffer[32];</div><div><span style="white-space:pre">	</span>sprintf(buffer, "%1.14g", points[0].x);</div><div><span style="white-space:pre">	</span>xml.append(buffer).append(" ");</div><div><span style="white-space:pre">	</span>sprintf(buffer, "%1.14g", points[0].y);</div><div><span style="white-space:pre">	</span>xml.append(buffer).append(" ");</div><div></div><div><span style="white-space:pre">	</span>xml.append("&lt;/gml:posList&gt;&lt;/gml:Point&gt;");</div><div>}</div></div><img src ="http://www.blogjava.net/brock/aggbug/408368.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-01-02 10:19 <a href="http://www.blogjava.net/brock/archive/2014/01/02/408368.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HelloJNI</title><link>http://www.blogjava.net/brock/archive/2013/12/30/408203.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Mon, 30 Dec 2013 06:18:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/12/30/408203.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/408203.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/12/30/408203.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/408203.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/408203.html</trackback:ping><description><![CDATA[写给自己看看<br />java --HelloJNI ---<br /><div>import java.io.UnsupportedEncodingException;</div><div></div><div></div><div>public class HelloJNI {</div><div><span style="white-space:pre">	</span> static {</div><div></div><div><span style="white-space:pre">	</span> &nbsp; &nbsp; &nbsp;System.loadLibrary("HelloJNI"); // hello.dll (Windows) or libhello.so (Unixes)</div><div><span style="white-space:pre">	</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; }</div><div><span style="white-space:pre">	</span> &nbsp; // A native method that receives nothing and returns void</div><div><span style="white-space:pre">	</span> &nbsp; private native void sayHello();</div><div><span style="white-space:pre">	</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; private native double sayOK(String dd);</div><div><span style="white-space:pre">	</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; private native void getFileGdb(String path);</div><div><span style="white-space:pre">	</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; private native String getFileGdbStr(String path);</div><div><span style="white-space:pre">	</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; private native GeodbEntity getGdbTable(GeodbEntity geo);</div><div><span style="white-space:pre">	</span>&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; /**</div><div><span style="white-space:pre">	</span> * @param args</div><div><span style="white-space:pre">	</span> * @throws UnsupportedEncodingException</div><div><span style="white-space:pre">	</span> */</div><div><span style="white-space:pre">	</span>/** &nbsp;</div><div><span style="white-space:pre">	</span> * @param args</div><div><span style="white-space:pre">	</span> * @throws UnsupportedEncodingException</div><div><span style="white-space:pre">	</span> */</div><div><span style="white-space:pre">	</span>public static void main(String[] args) throws UnsupportedEncodingException {</div><div><span style="white-space:pre">		</span>// &nbsp; System.out.println( System.getProperty("java.library.path"));</div><div><span style="white-space:pre">		</span> &nbsp; HelloJNI hello = &nbsp;new HelloJNI();</div><div>//<span style="white-space:pre">		</span> &nbsp; hello.sayHello(); &nbsp;// invoke the native method</div><div><span style="white-space:pre">		</span> &nbsp;&nbsp;</div><div>//<span style="white-space:pre">		</span> &nbsp; System.out.println(hello.sayOK("Apple"));</div><div>//<span style="white-space:pre">		</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">		</span> &nbsp; //hello.getFileGdb("D:/cpp/FileGDB_API_VS2012_1_3/samples/data/ExecuteSQL.gdb");</div><div><span style="white-space:pre">		</span> &nbsp; //GeodbEntity dd= hello.getGdbTable("D:/cpp/FileGDB_API_VS2012_1_3/samples/data/ExecuteSQL.gdb","dd");</div><div><span style="white-space:pre">		</span> &nbsp; GeodbEntity dd= new GeodbEntity();</div><div><span style="white-space:pre">		</span> &nbsp; dd.setTable("D:/cpp/FileGDB_API_VS2012_1_3/samples/data/ExecuteSQL.gdb 阿切尔");</div><div><span style="white-space:pre">		</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">		</span> &nbsp; hello.getGdbTable(dd);</div><div><span style="white-space:pre">		</span>&nbsp;</div><div><span style="white-space:pre">		</span> &nbsp;System.out.println("java"+dd.getSrid());</div><div><span style="white-space:pre">		</span> &nbsp;for(int i=0;i&lt;dd.getFieldValues().size();i++){</div><div><span style="white-space:pre">			</span> &nbsp;System.out.println(dd.getFieldValues().get(i));</div><div><span style="white-space:pre">			</span> &nbsp;</div><div><span style="white-space:pre">		</span> &nbsp;}</div><div><span style="white-space:pre">		</span> &nbsp;// System.out.println(hello.getFileGdbStr("D:/cpp/FileGDB_API_VS2012_1_3/samples/data/ExecuteSQL.gdb"));</div><div><span style="white-space:pre">		</span> &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span> &nbsp; }</div><div></div><div>}<br />-----GeodbEntity ----<br /><div>import java.util.List;</div><div>import java.util.ArrayList;</div><div></div><div>public class GeodbEntity {</div><div><span style="white-space:pre">	</span>//输入</div><div><span style="white-space:pre">	</span>private String table;</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>private String eodbPath;</div><div><span style="white-space:pre">	</span>//输出</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>/**列字段##隔开*/</div><div><span style="white-space:pre">	</span>private String Fields;</div><div><span style="white-space:pre">	</span>/**数据表##隔开*/</div><div><span style="white-space:pre">	</span>private ArrayList&lt;String&gt; FieldValues=new ArrayList&lt;String&gt;();</div><div><span style="white-space:pre">	</span>/**空间参考标识符*/</div><div><span style="white-space:pre">	</span>private String srid;</div><div><span style="white-space:pre">	</span>/**维度*/</div><div><span style="white-space:pre">	</span>private String dimension;</div><div><span style="white-space:pre">	</span></div><div></div><div><span style="white-space:pre">	</span>public String getTable() {</div><div><span style="white-space:pre">		</span>return table;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public void setTable(String table) {</div><div><span style="white-space:pre">		</span>this.table = table;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public String getEodbPath() {</div><div><span style="white-space:pre">		</span>return eodbPath;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public void setEodbPath(String eodbPath) {</div><div><span style="white-space:pre">		</span>this.eodbPath = eodbPath;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public String getSrid() {</div><div><span style="white-space:pre">		</span>return srid;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public void setSrid(String srid) {</div><div><span style="white-space:pre">		</span>this.srid = srid;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public String getDimension() {</div><div><span style="white-space:pre">		</span>return dimension;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public void setDimension(String dimension) {</div><div><span style="white-space:pre">		</span>this.dimension = dimension;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public String getFields() {</div><div><span style="white-space:pre">		</span>return Fields;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public void setFields(String fields) {</div><div><span style="white-space:pre">		</span>Fields = fields;</div><div><span style="white-space:pre">	</span>}</div><div></div><div></div><div></div><div><span style="white-space:pre">	</span>public ArrayList&lt;String&gt; getFieldValues() {</div><div><span style="white-space:pre">		</span>return FieldValues;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public void setFieldValues(ArrayList&lt;String&gt; fieldValues) {</div><div><span style="white-space:pre">		</span>FieldValues = fieldValues;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>public String toString() {</div><div><span style="white-space:pre">		</span></div><div>&nbsp; &nbsp; &nbsp; &nbsp; return Fields;</div><div>&nbsp; &nbsp; }</div><div></div><div>}</div><div></div>--c++</div><div>hellojni.h<br /><div>#define _Included_HelloJNI</div><div>#ifdef __cplusplus</div><div>extern "C" {</div><div>#endif</div><div>/*</div><div>&nbsp;* Class: &nbsp; &nbsp; HelloJNI</div><div>&nbsp;* Method: &nbsp; &nbsp;sayHello</div><div>&nbsp;* Signature: ()V</div><div>&nbsp;*/</div><div>JNIEXPORT void JNICALL Java_HelloJNI_sayHello</div><div>&nbsp; (JNIEnv *, jobject);</div><div></div><div>/*</div><div>&nbsp;* Class: &nbsp; &nbsp; HelloJNI</div><div>&nbsp;* Method: &nbsp; &nbsp;sayOK</div><div>&nbsp;* Signature: (Ljava/lang/String;)D</div><div>&nbsp;*/</div><div>JNIEXPORT jdouble JNICALL Java_HelloJNI_sayOK</div><div>&nbsp; (JNIEnv *, jobject, jstring);</div><div></div><div>/*</div><div>&nbsp;* Class: &nbsp; &nbsp; HelloJNI</div><div>&nbsp;* Method: &nbsp; &nbsp;getFileGdb</div><div>&nbsp;* Signature: (Ljava/lang/String;)V</div><div>&nbsp;*/</div><div>JNIEXPORT void JNICALL Java_HelloJNI_getFileGdb</div><div>&nbsp; (JNIEnv *, jobject, jstring);</div><div></div><div>/*</div><div>&nbsp;* Class: &nbsp; &nbsp; HelloJNI</div><div>&nbsp;* Method: &nbsp; &nbsp;getFileGdbStr</div><div>&nbsp;* Signature: (Ljava/lang/String;)Ljava/lang/String;</div><div>&nbsp;*/</div><div>JNIEXPORT jstring JNICALL Java_HelloJNI_getFileGdbStr</div><div>&nbsp; (JNIEnv *, jobject, jstring);</div><div></div><div>/*</div><div>&nbsp;* Class: &nbsp; &nbsp; HelloJNI</div><div>&nbsp;* Method: &nbsp; &nbsp;getGdbTable</div><div>&nbsp;* Signature: (LGeodbEntity;)LGeodbEntity;</div><div>&nbsp;*/</div><div>JNIEXPORT jobject JNICALL Java_HelloJNI_getGdbTable</div><div>&nbsp; (JNIEnv *, jobject, jobject);</div><div></div><div>#ifdef __cplusplus</div><div>}</div><div>#endif</div><div>#endif</div><div>----------hello c++------</div><br /><div>#include &lt;jni.h&gt;</div><div>#include &lt;stdio.h&gt;</div><div>#include &lt;iostream&gt;</div><div>#include &lt;string.h&gt;</div><div>#include "HelloJNI.h"</div><div>#include &lt;fstream&gt;</div><div>#include &lt;time.h&gt;</div><div></div><div>#include &lt;FileGDBAPI.h&gt;</div><div></div><div>using namespace std;</div><div>using namespace FileGDBAPI;</div><div></div><div>using namespace std;</div><div></div><div>&nbsp;</div><div>JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {</div><div><span style="white-space:pre">	</span>printf("Hello World!\n");</div><div><span style="white-space:pre">	</span>return;</div><div>}</div><div></div><div></div><div>JNIEXPORT jdouble JNICALL Java_HelloJNI_sayOK</div><div><span style="white-space:pre">	</span>(JNIEnv* env, jobject obj, jstring name){</div><div><span style="white-space:pre">		</span>const char* pname=env-&gt;GetStringUTFChars(name,NULL);</div><div><span style="white-space:pre">		</span>if(strcmp(pname,"Apple")==0){</div><div><span style="white-space:pre">			</span>env-&gt;ReleaseStringUTFChars(name,pname);</div><div><span style="white-space:pre">			</span>cout&lt;&lt;"After release:"&lt;&lt;pname&lt;&lt;endl;</div><div><span style="white-space:pre">			</span>return 1.2;</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>else{</div><div></div><div><span style="white-space:pre">			</span>env-&gt;ReleaseStringUTFChars(name,pname);</div><div><span style="white-space:pre">			</span>cout&lt;&lt;"After release:"&lt;&lt;pname&lt;&lt;endl;</div><div><span style="white-space:pre">			</span>return 2.1;</div><div></div><div><span style="white-space:pre">		</span>}</div><div>}</div><div></div><div>JNIEXPORT jstring JNICALL Java_HelloJNI_getFileGdbStr</div><div><span style="white-space:pre">	</span>(JNIEnv *env, jobject thisObj, jstring path){</div><div></div><div><span style="white-space:pre">		</span>/*<span style="white-space:pre">	</span>fgdbError hr;</div><div><span style="white-space:pre">		</span>wstring errorText;</div><div><span style="white-space:pre">		</span>Geodatabase geodatabase;</div><div></div><div><span style="white-space:pre">		</span>std::wstring value;</div><div><span style="white-space:pre">		</span>const jchar* raw = env-&gt;GetStringChars(path, NULL);</div><div><span style="white-space:pre">		</span>if (raw != NULL) {</div><div><span style="white-space:pre">		</span>jsize len = env-&gt;GetStringLength(path);</div><div><span style="white-space:pre">		</span>value.assign(raw, raw + len);</div><div><span style="white-space:pre">		</span>env-&gt;ReleaseStringChars(path, raw);</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>if ((hr = OpenGeodatabase(value, geodatabase)) != S_OK)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "An error occurred while opening the geodatabase." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>ErrorInfo::GetErrorDescription(hr, errorText);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; errorText &lt;&lt; "(" &lt;&lt; hr &lt;&lt; ")." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>return (env)-&gt;NewStringUTF("7");</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>Row &nbsp; &nbsp; attrQueryRow;</div><div><span style="white-space:pre">		</span>EnumRows attrQueryRows;</div><div><span style="white-space:pre">		</span>wstring sqlStatement(L"SELECT * FROM Cities WHERE TYPE = 'city' AND OBJECTID &lt; 10");</div><div><span style="white-space:pre">		</span>if ((hr = geodatabase.ExecuteSQL(sqlStatement, true, attrQueryRows)) != S_OK)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "An error occurred while performing the attribute query." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>ErrorInfo::GetErrorDescription(hr, errorText);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; errorText &lt;&lt; "(" &lt;&lt; hr &lt;&lt; ")." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>return (env)-&gt;NewStringUTF("7");</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>FieldInfo fieldInfo;</div><div><span style="white-space:pre">		</span>attrQueryRows.GetFieldInformation(fieldInfo);</div><div></div><div><span style="white-space:pre">		</span>int &nbsp; &nbsp; &nbsp; fieldCount;</div><div><span style="white-space:pre">		</span>FieldType fieldType;</div><div><span style="white-space:pre">		</span>wstring &nbsp; fieldName;</div><div></div><div><span style="white-space:pre">		</span>// Iterate through the returned rows printing out all field values.</div><div><span style="white-space:pre">		</span>short &nbsp; &nbsp; shortField;</div><div><span style="white-space:pre">		</span>int32 &nbsp; &nbsp; longField;</div><div><span style="white-space:pre">		</span>float &nbsp; &nbsp; floatField;</div><div><span style="white-space:pre">		</span>double &nbsp; &nbsp;doubleField;</div><div><span style="white-space:pre">		</span>string &nbsp; &nbsp;stringField;</div><div><span style="white-space:pre">		</span>wstring &nbsp; wstringField;</div><div><span style="white-space:pre">		</span>tm &nbsp; &nbsp; &nbsp; &nbsp;dateTimeField;</div><div><span style="white-space:pre">		</span>char &nbsp; &nbsp; &nbsp;datetime[80];</div><div><span style="white-space:pre">		</span>Guid &nbsp; &nbsp; &nbsp;globalIDField;</div><div><span style="white-space:pre">		</span>Guid &nbsp; &nbsp; &nbsp;guidField;</div><div><span style="white-space:pre">		</span>wstring &nbsp; strGuid;</div><div><span style="white-space:pre">		</span>wstring &nbsp; strGlobalID;</div><div><span style="white-space:pre">		</span>bool &nbsp; &nbsp; &nbsp;isNull;</div><div><span style="white-space:pre">		</span>byte * shapeBufferBytes ;</div><div><span style="white-space:pre">		</span>ShapeBuffer geometry;</div><div><span style="white-space:pre">		</span>ByteArray &nbsp;bss;</div><div><span style="white-space:pre">		</span>while (attrQueryRows.Next(attrQueryRow) == S_OK)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>fieldInfo.GetFieldCount(fieldCount);</div><div><span style="white-space:pre">		</span>for (long fieldNumber = 0; fieldNumber &lt; fieldCount; fieldNumber++)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>fieldInfo.GetFieldType(fieldNumber, fieldType);</div><div><span style="white-space:pre">		</span>fieldInfo.GetFieldName(fieldNumber, fieldName);</div><div><span style="white-space:pre">		</span>attrQueryRow.IsNull(fieldName, isNull);</div><div><span style="white-space:pre">		</span>if (!isNull)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>switch (fieldType)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>case fieldTypeSmallInteger:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetShort(fieldName, shortField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; &nbsp;shortField &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeInteger:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetInteger(fieldName, longField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; longField &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeSingle:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetFloat(fieldName, floatField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; floatField &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeDouble:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetDouble(fieldName, doubleField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; doubleField &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeString:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetString(fieldName, wstringField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; wstringField &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeDate:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetDate(fieldName, dateTimeField);</div><div><span style="white-space:pre">		</span>strftime(datetime,80,"%a %b %d %I:%M:%S%p %Y", &amp;dateTimeField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; datetime &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeOID:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetOID(longField);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; longField &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeGeometry:{</div><div><span style="white-space:pre">		</span>attrQueryRow.GetGeometry(geometry);</div><div></div><div><span style="white-space:pre">		</span>// attrQueryRow.GetBinary(fieldName, bss);</div><div><span style="white-space:pre">		</span>double x, y;</div><div></div><div><span style="white-space:pre">		</span>shapeBufferBytes = geometry.shapeBuffer;</div><div></div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "d::x::"&lt;&lt; x&lt;&lt;"y:"&lt;&lt;y&lt;&lt; '\t';;</div><div><span style="white-space:pre">		</span>wcout &lt;&lt;shapeBufferBytes&lt;&lt; "Geometry" &lt;&lt; '\t';}</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeBlob:</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "Blob" &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeGUID:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetGUID(fieldName, guidField);</div><div><span style="white-space:pre">		</span>guidField.ToString(strGuid);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; strGuid &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>case fieldTypeGlobalID:</div><div><span style="white-space:pre">		</span>attrQueryRow.GetGlobalID(globalIDField);</div><div><span style="white-space:pre">		</span>globalIDField.ToString(strGlobalID);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; strGlobalID &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>break;</div><div></div><div><span style="white-space:pre">		</span>default:</div><div><span style="white-space:pre">		</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>else</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "null" &lt;&lt; '\t';</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>wcout &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>attrQueryRows.Close(); // Close the EnumRows</div><div><span style="white-space:pre">		</span>*/</div><div><span style="white-space:pre">		</span>const char * pat="zhy好棒呀 第一个东东出来了";</div><div></div><div><span style="white-space:pre">		</span>//定义java String类 strClass &nbsp;</div><div><span style="white-space:pre">		</span>jclass strClass = (env)-&gt;FindClass("Ljava/lang/String;"); &nbsp;</div><div><span style="white-space:pre">		</span>//获取String(byte[],String)的构造器,用于将本地byte[]数组转换为一个新String &nbsp;</div><div><span style="white-space:pre">		</span>jmethodID ctorID = (env)-&gt;GetMethodID(strClass, "&lt;init&gt;", "([BLjava/lang/String;)V"); &nbsp;</div><div><span style="white-space:pre">		</span>//建立byte数组 &nbsp;</div><div><span style="white-space:pre">		</span>jbyteArray bytes = (env)-&gt;NewByteArray(strlen(pat)); &nbsp;</div><div><span style="white-space:pre">		</span>//将char* 转换为byte数组 &nbsp;</div><div><span style="white-space:pre">		</span>(env)-&gt;SetByteArrayRegion(bytes, 0, strlen(pat), (jbyte*)pat); &nbsp;</div><div><span style="white-space:pre">		</span>// 设置String, 保存语言类型,用于byte数组转换至String时的参数 &nbsp;</div><div><span style="white-space:pre">		</span>jstring encoding = (env)-&gt;NewStringUTF("GB2312"); &nbsp;&nbsp;</div><div><span style="white-space:pre">		</span>//将byte数组转换为java String,并输出 &nbsp;</div><div><span style="white-space:pre">		</span>return (jstring)(env)-&gt;NewObject(strClass, ctorID, bytes, encoding); &nbsp;</div><div></div><div></div><div><span style="white-space:pre">		</span>//return path;</div><div></div><div>}</div><div></div><div></div><div>JNIEXPORT void JNICALL Java_HelloJNI_getFileGdb(JNIEnv *env, jobject thisObj, jstring path) {</div><div></div><div><span style="white-space:pre">	</span>fgdbError hr;</div><div><span style="white-space:pre">	</span>wstring errorText;</div><div><span style="white-space:pre">	</span>Geodatabase geodatabase;</div><div><span style="white-space:pre">	</span>// const wchar_t * szStr =(wchar_t * )env-&gt;GetStringChars(path, NULL);</div><div><span style="white-space:pre">	</span>std::wstring value;</div><div><span style="white-space:pre">	</span>const jchar* raw = env-&gt;GetStringChars(path, NULL);</div><div><span style="white-space:pre">	</span>if (raw != NULL) {</div><div><span style="white-space:pre">		</span>jsize len = env-&gt;GetStringLength(path);</div><div><span style="white-space:pre">		</span>value.assign(raw, raw + len);</div><div><span style="white-space:pre">		</span>env-&gt;ReleaseStringChars(path, raw);</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>if ((hr = OpenGeodatabase(value, geodatabase)) != S_OK)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "An error occurred while opening the geodatabase." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>ErrorInfo::GetErrorDescription(hr, errorText);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; errorText &lt;&lt; "(" &lt;&lt; hr &lt;&lt; ")." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>return;</div><div><span style="white-space:pre">	</span>}</div><div></div><div></div><div><span style="white-space:pre">	</span>wstring sqlStatement(L"SELECT CITY_NAME, POP1990 FROM Cities WHERE TYPE = 'city' AND OBJECTID &lt; 10");</div><div><span style="white-space:pre">	</span>EnumRows attrQueryRows;</div><div><span style="white-space:pre">	</span>if ((hr = geodatabase.ExecuteSQL(sqlStatement, true, attrQueryRows)) != S_OK)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "An error occurred while performing the attribute query." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>ErrorInfo::GetErrorDescription(hr, errorText);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; errorText &lt;&lt; "(" &lt;&lt; hr &lt;&lt; ")." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>return ;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>// Iterate through the returned rows.</div><div><span style="white-space:pre">	</span>Row &nbsp; &nbsp; attrQueryRow;</div><div><span style="white-space:pre">	</span>int32 &nbsp; cityPop;</div><div><span style="white-space:pre">	</span>wstring cityName;</div><div><span style="white-space:pre">	</span>while (attrQueryRows.Next(attrQueryRow) == S_OK)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>attrQueryRow.GetInteger(L"POP1990", cityPop);</div><div><span style="white-space:pre">		</span>attrQueryRow.GetString(L"CITY_NAME", cityName);</div><div></div><div><span style="white-space:pre">		</span>wcout &lt;&lt; cityName &lt;&lt; '\t' &lt;&lt; cityPop &lt;&lt; endl;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>// SELECT * - Return all fields.</div><div><span style="white-space:pre">	</span>sqlStatement.assign(L"SELECT * FROM Cities WHERE TYPE = 'city' AND OBJECTID &lt; 10");</div><div><span style="white-space:pre">	</span>if ((hr = geodatabase.ExecuteSQL(sqlStatement, true, attrQueryRows)) != S_OK)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "An error occurred while performing the attribute query." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>ErrorInfo::GetErrorDescription(hr, errorText);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; errorText &lt;&lt; "(" &lt;&lt; hr &lt;&lt; ")." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>return;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>// Get the field type and name from the row enumerator.</div><div><span style="white-space:pre">	</span>FieldInfo fieldInfo;</div><div><span style="white-space:pre">	</span>attrQueryRows.GetFieldInformation(fieldInfo);</div><div></div><div><span style="white-space:pre">	</span>int &nbsp; &nbsp; &nbsp; fieldCount;</div><div><span style="white-space:pre">	</span>FieldType fieldType;</div><div><span style="white-space:pre">	</span>wstring &nbsp; fieldName;</div><div></div><div><span style="white-space:pre">	</span>// Iterate through the returned rows printing out all field values.</div><div><span style="white-space:pre">	</span>short &nbsp; &nbsp; shortField;</div><div><span style="white-space:pre">	</span>int32 &nbsp; &nbsp; longField;</div><div><span style="white-space:pre">	</span>float &nbsp; &nbsp; floatField;</div><div><span style="white-space:pre">	</span>double &nbsp; &nbsp;doubleField;</div><div><span style="white-space:pre">	</span>string &nbsp; &nbsp;stringField;</div><div><span style="white-space:pre">	</span>wstring &nbsp; wstringField;</div><div><span style="white-space:pre">	</span>tm &nbsp; &nbsp; &nbsp; &nbsp;dateTimeField;</div><div><span style="white-space:pre">	</span>char &nbsp; &nbsp; &nbsp;datetime[80];</div><div><span style="white-space:pre">	</span>Guid &nbsp; &nbsp; &nbsp;globalIDField;</div><div><span style="white-space:pre">	</span>Guid &nbsp; &nbsp; &nbsp;guidField;</div><div><span style="white-space:pre">	</span>wstring &nbsp; strGuid;</div><div><span style="white-space:pre">	</span>wstring &nbsp; strGlobalID;</div><div><span style="white-space:pre">	</span>bool &nbsp; &nbsp; &nbsp;isNull;</div><div><span style="white-space:pre">	</span>byte * shapeBufferBytes ;</div><div><span style="white-space:pre">	</span>ShapeBuffer geometry;</div><div></div><div></div><div><span style="white-space:pre">	</span>while (attrQueryRows.Next(attrQueryRow) == S_OK)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>fieldInfo.GetFieldCount(fieldCount);</div><div><span style="white-space:pre">		</span>for (long fieldNumber = 0; fieldNumber &lt; fieldCount; fieldNumber++)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>fieldInfo.GetFieldType(fieldNumber, fieldType);</div><div><span style="white-space:pre">			</span>fieldInfo.GetFieldName(fieldNumber, fieldName);</div><div><span style="white-space:pre">			</span>attrQueryRow.IsNull(fieldName, isNull);</div><div><span style="white-space:pre">			</span>if (!isNull)</div><div><span style="white-space:pre">			</span>{</div><div><span style="white-space:pre">				</span>switch (fieldType)</div><div><span style="white-space:pre">				</span>{</div><div><span style="white-space:pre">				</span>case fieldTypeSmallInteger:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetShort(fieldName, shortField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; &nbsp;shortField &lt;&lt; endl;</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeInteger:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetInteger(fieldName, longField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; longField &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeSingle:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetFloat(fieldName, floatField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; floatField &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeDouble:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetDouble(fieldName, doubleField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; doubleField &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeString:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetString(fieldName, wstringField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; wstringField &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeDate:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetDate(fieldName, dateTimeField);</div><div><span style="white-space:pre">					</span>strftime(datetime,80,"%a %b %d %I:%M:%S%p %Y", &amp;dateTimeField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; datetime &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeOID:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetOID(longField);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; longField &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeGeometry:{</div><div><span style="white-space:pre">					</span>attrQueryRow.GetGeometry(geometry);</div><div></div><div><span style="white-space:pre">					</span>// attrQueryRow.GetBinary(fieldName, bss);</div><div><span style="white-space:pre">					</span>double x, y;</div><div></div><div><span style="white-space:pre">					</span>shapeBufferBytes = geometry.shapeBuffer;</div><div></div><div><span style="white-space:pre">					</span>memcpy(&amp;x, geometry.shapeBuffer + 4, sizeof(x));</div><div></div><div><span style="white-space:pre">					</span>memcpy(&amp;y, geometry.shapeBuffer + 12, sizeof(y));</div><div></div><div><span style="white-space:pre">					</span>//std::string *str3 = new std::string((char *)shapeBufferBytes);</div><div></div><div><span style="white-space:pre">					</span>wcout &lt;&lt; "d::x::"&lt;&lt; x&lt;&lt;"y:"&lt;&lt;y&lt;&lt; '\t';;</div><div><span style="white-space:pre">					</span>wcout &lt;&lt;shapeBufferBytes&lt;&lt; "Geometry" &lt;&lt; '\t';}</div><div><span style="white-space:pre">									</span> &nbsp; break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeBlob:</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; "Blob" &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeGUID:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetGUID(fieldName, guidField);</div><div><span style="white-space:pre">					</span>guidField.ToString(strGuid);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; strGuid &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>case fieldTypeGlobalID:</div><div><span style="white-space:pre">					</span>attrQueryRow.GetGlobalID(globalIDField);</div><div><span style="white-space:pre">					</span>globalIDField.ToString(strGlobalID);</div><div><span style="white-space:pre">					</span>wcout &lt;&lt; strGlobalID &lt;&lt; '\t';</div><div><span style="white-space:pre">					</span>break;</div><div></div><div><span style="white-space:pre">				</span>default:</div><div><span style="white-space:pre">					</span>break;</div><div><span style="white-space:pre">				</span>}</div><div><span style="white-space:pre">			</span>}</div><div><span style="white-space:pre">			</span>else</div><div><span style="white-space:pre">			</span>{</div><div><span style="white-space:pre">				</span>wcout &lt;&lt; "null" &lt;&lt; '\t';</div><div><span style="white-space:pre">			</span>}</div><div><span style="white-space:pre">		</span>}</div><div></div><div><span style="white-space:pre">		</span>wcout &lt;&lt; endl;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>attrQueryRows.Close(); // Close the EnumRows</div><div></div><div><span style="white-space:pre">	</span>// Close the geodatabase</div><div><span style="white-space:pre">	</span>if ((hr = CloseGeodatabase(geodatabase)) != S_OK)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; "An error occurred while closing the geodatabase." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>ErrorInfo::GetErrorDescription(hr, errorText);</div><div><span style="white-space:pre">		</span>wcout &lt;&lt; errorText &lt;&lt; "(" &lt;&lt; hr &lt;&lt; ")." &lt;&lt; endl;</div><div><span style="white-space:pre">		</span>return ;</div><div><span style="white-space:pre">	</span>}</div><div></div><div></div><div><span style="white-space:pre">	</span>printf("Hello World &nbsp;geodatebase!\n");</div><div><span style="white-space:pre">	</span>return;</div><div>}</div><div></div><div>std::string jstring2str(JNIEnv* env, jstring jstr) &nbsp;</div><div>{ &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; char* &nbsp; rtn &nbsp; = &nbsp; NULL; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; jclass &nbsp; clsstring &nbsp; = &nbsp; env-&gt;FindClass("java/lang/String"); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; jstring &nbsp; strencode &nbsp; = &nbsp; env-&gt;NewStringUTF("GB2312"); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; jmethodID &nbsp; mid &nbsp; = &nbsp; env-&gt;GetMethodID(clsstring, &nbsp; "getBytes", &nbsp; "(Ljava/lang/String;)[B"); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; jbyteArray &nbsp; barr= &nbsp; (jbyteArray)env-&gt;CallObjectMethod(jstr,mid,strencode); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; jsize &nbsp; alen &nbsp; = &nbsp; env-&gt;GetArrayLength(barr); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; jbyte* &nbsp; ba &nbsp; = &nbsp; env-&gt;GetByteArrayElements(barr,JNI_FALSE); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; if(alen &nbsp; &gt; &nbsp; 0) &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; { &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; rtn &nbsp; = &nbsp; (char*)malloc(alen+1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; memcpy(rtn,ba,alen); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; rtn[alen]=0; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; } &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; env-&gt;ReleaseByteArrayElements(barr,ba,0); &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; std::string stemp(rtn); &nbsp;</div><div>&nbsp; &nbsp; free(rtn); &nbsp;</div><div>&nbsp; &nbsp; return &nbsp; stemp; &nbsp; &nbsp;&nbsp;</div><div>} &nbsp;</div><div></div><div></div><div></div><div>jstring str2jstring(JNIEnv* env,const char* pat) &nbsp;</div><div>{ &nbsp;</div><div>&nbsp; &nbsp; //定义java String类 strClass &nbsp;</div><div>&nbsp; &nbsp; jclass strClass = (env)-&gt;FindClass("Ljava/lang/String;"); &nbsp;</div><div>&nbsp; &nbsp; //获取String(byte[],String)的构造器,用于将本地byte[]数组转换为一个新String &nbsp;</div><div>&nbsp; &nbsp; jmethodID ctorID = (env)-&gt;GetMethodID(strClass, "&lt;init&gt;", "([BLjava/lang/String;)V"); &nbsp;</div><div>&nbsp; &nbsp; //建立byte数组 &nbsp;</div><div>&nbsp; &nbsp; jbyteArray bytes = (env)-&gt;NewByteArray(strlen(pat)); &nbsp;</div><div>&nbsp; &nbsp; //将char* 转换为byte数组 &nbsp;</div><div>&nbsp; &nbsp; (env)-&gt;SetByteArrayRegion(bytes, 0, strlen(pat), (jbyte*)pat); &nbsp;</div><div>&nbsp; &nbsp; // 设置String, 保存语言类型,用于byte数组转换至String时的参数 &nbsp;</div><div>&nbsp; &nbsp; jstring encoding = (env)-&gt;NewStringUTF("GB2312"); &nbsp;&nbsp;</div><div>&nbsp; &nbsp; //将byte数组转换为java String,并输出 &nbsp;</div><div>&nbsp; &nbsp; return (jstring)(env)-&gt;NewObject(strClass, ctorID, bytes, encoding); &nbsp;</div><div>} &nbsp;</div><div></div><div></div><div></div><div>JNIEXPORT jobject JNICALL Java_HelloJNI_getGdbTable(JNIEnv *env, jobject obj,jobject _GeodbEntity){</div><div></div><div><span style="white-space:pre">	</span>const char * dd="4096";</div><div><span style="white-space:pre">	</span>//jclass userClass = env-&gt;FindClass("GeodbEntity"); &nbsp;</div><div>jclass userClass=env-&gt;GetObjectClass(_GeodbEntity);&nbsp;</div><div><span style="white-space:pre">	</span>//jmethodID userMethod = env-&gt;GetMethodID(userClass,"&lt;init&gt;","()V");&nbsp;</div><div></div><div><span style="white-space:pre">	</span>//jobject userObject = env-&gt;NewObject(userClass,userMethod); &nbsp;</div><div></div><div><span style="white-space:pre">	</span>//jmethodID construction_id = env-&gt;GetMethodID(userClass, "&lt;init&gt;", "()V");&nbsp;</div><div></div><div>//得到构造方法的ID</div><div>&nbsp; &nbsp; //jobject userObject = env-&gt;NewObject(userClass, construction_id);&nbsp;</div><div></div><div><span style="white-space:pre">	</span>//jobject &nbsp; userObject = env-&gt;AllocObject(userClass); &nbsp; &nbsp;&nbsp;</div><div></div><div><span style="white-space:pre">	</span>//</div><div><span style="white-space:pre">	</span>//jmethodID setName_method=env-&gt;GetMethodID(userClass,"setSrid","(Ljava/lang/String;)V");</div><div></div><div><span style="white-space:pre">	</span>//env-&gt;CallVoidMethod(userObject,setName_method,dd);</div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;//jclass objectClass = (env)-&gt;FindClass("GeodbEntity</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp;jmethodID methodId=env-&gt;GetMethodID(userClass,"getTable","()Ljava/lang/String;");</div><div>&nbsp;//调用customer对象的特定方法getName</div><div>&nbsp; &nbsp; &nbsp; &nbsp;jstring js_name=(jstring)env-&gt;CallObjectMethod(_GeodbEntity,methodId,NULL);</div><div></div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;//jfieldID table = (env)-&gt;GetFieldID(userClass,"table","Ljava/lang/String;");</div><div></div><div><span style="white-space:pre">		</span>//jchar dd=(env)-&gt;GetCharField(userClass,table);</div><div></div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;//std::string value;</div><div><span style="white-space:pre">		</span>//const jchar* raw = env-&gt;GetStringChars(js_name, NULL);</div><div><span style="white-space:pre">		</span>//if (raw != NULL) {</div><div><span style="white-space:pre">		</span>//jsize len = env-&gt;GetStringLength(js_name);</div><div><span style="white-space:pre">		</span>//value.assign(raw, raw + len);</div><div><span style="white-space:pre">		</span>//env-&gt;ReleaseStringChars(js_name, raw);</div><div><span style="white-space:pre">		</span>//}</div><div><span style="white-space:pre">		</span>cout&lt;&lt;jstring2str(env,js_name)&lt;&lt;endl;</div><div></div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;jfieldID str = (env)-&gt;GetFieldID(userClass,"srid","Ljava/lang/String;");</div><div></div><div><span style="white-space:pre">	</span> &nbsp; (env)-&gt;SetObjectField(_GeodbEntity,str,(env)-&gt;NewStringUTF(dd));</div><div></div><div></div><div></div><div></div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;//获取arraylist 类</div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;jclass cls_ArrayList = env-&gt;FindClass("java/util/ArrayList");</div><div><span style="white-space:pre">		</span>//获得arraylist id</div><div>&nbsp; &nbsp; &nbsp; &nbsp; jmethodID construct = env-&gt;GetMethodID(cls_ArrayList,"&lt;init&gt;","()V"); &nbsp;</div><div></div><div><span style="white-space:pre">		</span>//创建arraylist</div><div>&nbsp; &nbsp; &nbsp; &nbsp; jobject obj_ArrayList = env-&gt;NewObject(cls_ArrayList,construct);&nbsp;</div><div></div><div></div><div><span style="white-space:pre">		</span>//获取 arraylist 的add 方法</div><div>&nbsp; &nbsp; &nbsp; &nbsp; jmethodID arrayList_add = env-&gt;GetMethodID(cls_ArrayList,"add","(Ljava/lang/Object;)Z"); &nbsp;</div><div></div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>for(int i=0;i&lt;10;i++){</div><div></div><div><span style="white-space:pre">			</span> jobject alistadd = (env)-&gt;NewStringUTF("my name is D:"+i);&nbsp;</div><div></div><div><span style="white-space:pre">			</span> //通过 add 方法 添加数据到 arraylist中</div><div><span style="white-space:pre">			</span> env-&gt;CallObjectMethod(obj_ArrayList,arrayList_add,alistadd); &nbsp;</div><div><span style="white-space:pre">		</span>}</div><div></div><div></div><div><span style="white-space:pre">		</span>jfieldID str1 = (env)-&gt;GetFieldID(userClass,"FieldValues","Ljava/util/ArrayList;");</div><div></div><div><span style="white-space:pre">	</span> &nbsp; (env)-&gt;SetObjectField(_GeodbEntity,str1,obj_ArrayList);</div><div></div><div></div><div><span style="white-space:pre">	</span>return _GeodbEntity;</div><div>}</div><div></div><br /><br /><br /></div><img src ="http://www.blogjava.net/brock/aggbug/408203.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-12-30 14:18 <a href="http://www.blogjava.net/brock/archive/2013/12/30/408203.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Windows环境下libxml2库的使用小结</title><link>http://www.blogjava.net/brock/archive/2013/12/25/408023.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 25 Dec 2013 06:49:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/12/25/408023.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/408023.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/12/25/408023.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/408023.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/408023.html</trackback:ping><description><![CDATA[<p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">-环境的搭建，<span style="font-size: 13px;">下载与安装LIBXML2和ICONV</span></p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Libxml2是一个C语言的XML程序库，可以简单方便的提供对XML文档的各种操作，并且支持XPATH查询，以及部分的支持XSLT转换等功能。Libxml2的下载地址是<a href="http://xmlsoft.org/downloads.html" style="color: #336699; text-decoration: none;">http://xmlsoft.org/downloads.html</a><a href="http://xmlsoft.org/" style="color: #336699; text-decoration: none;"></a>，完全版的库是开源的，并且带有例子程序和说明文档。完全版的文件名为:libxml2-2.7.8.tar.gz。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Libxml2中默认的内码是UTF-8，所有使用libxml2进行处理的xml文件，必须首先显式或者默认的转换为UTF-8编码才能被处理。<br />要在xml中使用中文，就必须能够在UTF-8和GB2312内码（较常用的一种简体中文编码）之间进行转换。Libxml2提供了默认的内码转换机制，并且在libxml2的Tutorial中有一个例子，事实证明这个例子并不适合用来转换中文。所以需要我们显式的使用ICONV来进行内码转换，libxml2本身也是ICONV使用进行转换的。ICONV是一个专门用来进行编码转换的库，基本上支持目前所有常用的编码。它是glibc库的一个部分，常常被用于UNIX系统中。当然，在windows下面使用也没有任何问题。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">其下载地址是<a href="http://gnuwin32.sourceforge.net/packages/libiconv.htm" style="color: #336699; text-decoration: none;">http://gnuwin32.sourceforge.net/packages/libiconv.htm</a>，文件名为libiconv-1.9.2-1-lib.zip。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 将libiconv-1.9.2-1-lib.zip解压，将其中的iconv.h放入C:\opt\include目录中，将其中的libiconv.lib放入C:\opt\lib中，并改名为iconv.lib.(没有opt目录就新建一个)。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 解压libxml2-2.7.8.tar.gz文件到C盘根目录，在c:\libxml2-2.7.8\libxml2-2.7.8\win32目录中存放了多个Windows平台编译器的Makefile文件，我们使用vs2008，所以待会会用Makefile.msvc文件。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">1.进入Visual Studio 2008 Command Prompt；</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">2.cd c:\libxml2-2.7.8\libxml2-2.7.8\win32</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">3.输入cscript configure.js compiler=msvc prefix=c:\opt&nbsp; include=c:\opt\include lib=c:\opt\lib debug=yes，回车执行。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">4.最后使用nmake命令进行编译，输入nmake /f Makefile.msvc并回车。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">此时会出现一下错误提示，</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">Makefile.msvc(465) : fatal error U1020: end-of-file found before next directive<br />Stop.</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">网上找了下原因，原来是Makefile.msvc中存在错误。</p><div style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">+!if "$(WITH_ICU)" == "1"</div><div style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">+LIBS = $(LIBS) icu.lib</div><div style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">+!endif</div><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">将以上三行前面的+号都删掉，重新执行nmake即可。</p><p style="background-color: #ffffff; color: #333333; font-family: Arial; line-height: 26px;">在当前win32目录中生成了一个bin.msvc目录，其中就有开发需要的libxml2.lib和libxml2.dll文件。</p><img src ="http://www.blogjava.net/brock/aggbug/408023.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-12-25 14:49 <a href="http://www.blogjava.net/brock/archive/2013/12/25/408023.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>