Tuesday, July 14, 2009

Can someone convert the code to java...... !!!?

////////////////////////////////////////...


// ShapeFileReader.cpp: implementation of the ShapeFileReader class.


//////////////////////////////////////...





#include "iostream.h"


#include "fstream.h"





#include "ShapeFileReader.h"


#include "MainHeader.h"


#include "RecordHeader.h"


#include "Point.h"


#include "Polygon.h"


#include "MultiPoint.h"


#include "PolyLine.h"





const char* FILENAME = "c:/shapes/cities.shp";


int getTotalShapes();





MainHeader mh;


Point *pt;


MultiPoint *mp;


Polygon *pg;


PolyLine *pl;





void main()


{


RecordHeader rh;


ifstream inp;


int index=0;





int l_totalShapes = getTotalShapes();





inp.open(FILENAME,ios::in, filebuf::openprot);


inp.setmode(filebuf::binary);


inp.read((char*)%26amp;mh, 100);





cout %26lt;%26lt; "\n File Code = " %26lt;%26lt; mh.getFileCode();


cout %26lt;%26lt; "\n File Length = " %26lt;%26lt; mh.getFileLength();


cout %26lt;%26lt; "\n Version = " %26lt;%26lt; mh.getVersion();


cout %26lt;%26lt; "\n Shape Type = " %26lt;%26lt; mh.getShapeType();


cout %26lt;%26lt; "\n xMin = " %26lt;%26lt; mh.getXMin();


cout %26lt;%26lt; "\n yMin = " %26lt;%26lt; mh.getYMin();


cout %26lt;%26lt; "\n xMax = " %26lt;%26lt; mh.getXMax();


cout %26lt;%26lt; "\n yMax = " %26lt;%26lt; mh.getYMax();


cout %26lt;%26lt; "\n zMin = " %26lt;%26lt; mh.getZMin();


cout %26lt;%26lt; "\n zMax = " %26lt;%26lt; mh.getZMax();


cout %26lt;%26lt; "\n mMin = " %26lt;%26lt; mh.getMMin();


cout %26lt;%26lt; "\n mMax = " %26lt;%26lt; mh.getMMax();





cout %26lt;%26lt; "\n Total shapes = " %26lt;%26lt; l_totalShapes;





switch (mh.getShapeType())


{


case POINT:


pt = new Point[l_totalShapes];


break;


case POLYLINE:


pl = new PolyLine[l_totalShapes];


break;


case POLYGON:


pg = new Polygon[l_totalShapes];


break;


case MULTIPOINT:


mp = new MultiPoint[l_totalShapes];


break;


}





while (index %26lt; l_totalShapes)


{


inp.read((char*)%26amp;rh,8);


if(inp.eof())


break;








switch(mh.getShapeType())


{


case POINT:


inp.read((char*)(pt+index),20);


break;





case POLYLINE:


{


int *l_ptrParts = NULL;


struct point *l_ptrPoints = NULL;





inp.read((char*)(pl+index),44);





l_ptrParts = new int[pl[index].getNumParts()];


l_ptrPoints = new struct point[pl[index].getNumPoints()];


pl[index].setParts(l_ptrParts);


pl[index].setPoints(l_ptrPoints);





inp.read((char*)l_ptrParts, (sizeof(int)*pl[index].getNumParts()));


inp.read((char*)l_ptrPoints, (sizeof(struct point)*pl[index].getNumPoints()));





}


break;





case POLYGON:


{


int *l_ptrParts = NULL;


struct point *l_ptrPoints = NULL;





inp.read((char*)(pg+index),44);





l_ptrParts = new int[pg[index].getNumParts()];


l_ptrPoints = new struct point[pg[index].getNumPoints()];


pg[index].setParts(l_ptrParts);


pg[index].setPoints(l_ptrPoints);





inp.read((char*)l_ptrParts, (sizeof(int)*pg[index].getNumParts()));


inp.read((char*)l_ptrPoints, (sizeof(struct point)*pg[index].getNumPoints()));





}


break;





case MULTIPOINT:


{


struct point *l_ptrPoints = NULL;





inp.read((char*)(mp+index),40);





l_ptrPoints = new struct point[mp[index].getNumPoints()];


mp[index].setPoints(l_ptrPoints);





inp.read((char*)l_ptrPoints, (sizeof(struct point)*mp[index].getNumPoints()));


}


break;





default:


cout %26lt;%26lt; "\n The shape type " %26lt;%26lt; mh.getShapeType () %26lt;%26lt; " is not handled yet\n";


}





// Increment index to point to next shape object in the shape array


index ++;


}





inp.close();


}





/*************************************...


* getTotalShapes


* @return int Returns the total number of shapes in the shape file


**************************************...





int getTotalShapes()


{


ifstream inp;


RecordHeader rh;





int l_shapeCount = 0;





inp.open(FILENAME, ios::in, filebuf::openprot);


inp.setmode(filebuf::binary);





inp.seekg(100, ios::beg);





while(!inp.eof())


{


inp.read((char*)%26amp;rh,8);


if(inp.eof())


break;


inp.seekg(rh.getContentLength()*2, ios::cur);


l_shapeCount++;


}





inp.close();





return l_shapeCount;


}

Can someone convert the code to java...... !!!?
If you are still stuck, may be you can contact a java expert at websites like http://askexpert.info/ to help you finish your assignment.
Reply:go to rentacoder.com


pay some money and someone could do it for u


i think it will cost u about 10$


No comments:

Post a Comment