📄 esrishapefile.cs
字号:
right = BinaryFile.ReadDouble();
top = BinaryFile.ReadDouble();
partcount = BinaryFile.ReadInt32();
pointcount = BinaryFile.ReadInt32();
int[] parts = new int[partcount];
int[] partspos = new int[partcount];
double[] xpoints = new double[pointcount];
double[] ypoints = new double[pointcount];
double[] zpoints = new double[pointcount];
//firstly read out parts begin pos in file
for (int j = 0; j < partcount; j++)
{
parts[j] =BinaryFile.ReadInt32();
}
//shift them to be points count included in parts
if (partcount > 0)
partspos[0] = 0;
int newpos = 0;
for (int j = 0; j <= partcount - 2; j++)
{
parts[j] = parts[j + 1] - parts[j];
newpos += parts[j];
partspos[j + 1] = newpos;
}
parts[partcount - 1] = pointcount - parts[partcount - 1];
//read out coordinates
for (int j = 0; j < pointcount; j++)
{
x = BinaryFile.ReadDouble();
y = BinaryFile.ReadDouble();
xpoints[j] = x;
ypoints[j] = y;
zpoints[j] = 0;
}
if (pointcount > 1)
{
CGGeoShape.CGGeoPolygon gl = new CGGeoShape.CGGeoPolygon(xpoints, ypoints, zpoints, parts, partspos, pointcount, partcount);
gl.envlope.left = left;
gl.envlope.right = right;
gl.envlope.top = top;
gl.envlope.bottom = bottom;
gl.objectID = i;
gl.objectUID = i;
geolayer.getDataContainer().Add(gl);
}
}
break;
default:
return false;
}
}
catch (FileNotFoundException e)
{
e.ToString();
}
/*
cgClsLib.cgMapStock.cgGeoLayer geolayer = adapter.getMasterGeoLayer();
if (geolayer==null)
return false;
try{
// build stream connection
String fullname = adapter.getPath()+adapter.getFileName();
String idxfilename = fullname.Substring(0,fullname.LastIndexOf("\\"))+".shx";
FileInputStream in00 = new FileInputStream(fullname);
ByteBuffer bb0 = ByteBuffer.allocate(in00.available());
in00.read(bb0.array());
bb0.order(ByteOrder.LITTLE_ENDIAN);
in00 = null;
FileInputStream in10 = new FileInputStream(idxfilename);
ByteBuffer bb1 = ByteBuffer.allocate(in10.available());
in10.read(bb1.array());
bb1.order(ByteOrder.LITTLE_ENDIAN);
in10 = null;
int shapecount = (bb1.capacity()-100)/8;
//Get Shape Index Information
ESRI_IndexRec[] indexRecs = new ESRI_IndexRec[shapecount];
bb1.position(100);
for( int ii = 0 ; ii< shapecount; ii++)
{
indexRecs[ii] = new ESRI_IndexRec();
indexRecs[ii].Offset = bb1.getInt();
indexRecs[ii].ContentLen = bb1.getInt();
indexRecs[ii].Offset=((indexRecs[ii].Offset<<24&0xff000000)|(indexRecs[ii].Offset<<8 &0x00ff0000)|(indexRecs[ii].Offset>>8 &0x0000ff00)|(indexRecs[ii].Offset>>24&0x000000ff))<<1;
}
//Get Shape Outline Information
bb0.position(32);
int nshapetype = bb0.getInt();
geolayer.envlope.left = BinaryFile.ReadDouble();();
geolayer.envlope.bottom = BinaryFile.ReadDouble();();
geolayer.envlope.right = BinaryFile.ReadDouble();();
geolayer.envlope.top =BinaryFile.ReadDouble();();
//Get Shape Data From Here On
int stype;
double x , y ;
double left, right, top, bottom;
int partcount;
int pointcount;
switch(nshapetype){
case 1://single point
geolayer.shapeType = MKShapeType.SHAPE_POINT;
for(int i=0; i<shapecount; i++){
MKGeoPoint gps = new MKGeoPoint();
bb0.position(indexRecs[i].Offset+8);
stype = bb0.getInt();
x = BinaryFile.ReadDouble();();
y = BinaryFile.ReadDouble();();
if (stype!=nshapetype)
continue;
gps.objectID = i;
gps.objectUID = i;
gps.x = x;
gps.y = y;
gps.z = 0;
gps.envlope.left = gps.x;
gps.envlope.right = gps.x;
gps.envlope.top = gps.y;
gps.envlope.bottom = gps.y;
geolayer.getDataContainer().add(gps);
}
break;
case 8://multi points layer
break;
case 3://Polyline layer
geolayer.shapeType = MKShapeType.SHAPE_LINE;
for(int i=0; i<shapecount; i++){
int pos = indexRecs[i].Offset+8;
bb0.position(pos);
stype = bb0.getInt();
if (stype!=nshapetype){
continue;
}
left = BinaryFile.ReadDouble();();
bottom = BinaryFile.ReadDouble();();
right = BinaryFile.ReadDouble();();
top = BinaryFile.ReadDouble();();
partcount = bb0.getInt();
pointcount = bb0.getInt();
int[] parts = new int[partcount];
int[] partspos = new int[partcount];
double[] xpoints = new double[pointcount];
double[] ypoints = new double[pointcount];
double[] zpoints = new double[pointcount];
//firstly read out parts begin pos in file
for(int j = 0; j < partcount;j++){
parts[j]= bb0.getInt();
}
//shift them to be points count included in parts
if (partcount > 0)
partspos[0]=0;
int newpos=0;
for(int j = 0; j <= partcount-2;j++){
parts[j]= parts[j+1] - parts[j];
newpos+=parts[j];
partspos[j+1]=newpos;
}
parts[partcount-1]=pointcount-parts[partcount-1];
//read out coordinates
for(int j = 0 ; j < pointcount;j++){
x= BinaryFile.ReadDouble();();
y= BinaryFile.ReadDouble();();
xpoints[j] = x;
ypoints[j] = y;
zpoints[j] = 0;
}
if (pointcount > 1){
cgClsLib.cgGeoObject.cgGeoLine gl = new cgClsLib.cgGeoObject.cgGeoLine(xpoints,ypoints,zpoints,parts,partspos,pointcount,partcount);
gl.envlope.left = left;
gl.envlope.right = right;
gl.envlope.top = top;
gl.envlope.bottom = bottom;
gl.objectID = i;
gl.objectUID = i;
geolayer.getDataContainer().add(gl);
}
}
break;
case 5://Polygon layer
geolayer.shapeType = MKShapeType.SHAPE_POLYGON;
for(int i=0; i<shapecount; i++){
bb0.rewind();
bb0.position(indexRecs[i].Offset+8);
stype = bb0.getInt();
if (stype!=nshapetype){
continue;
}
left = BinaryFile.ReadDouble();();
bottom = BinaryFile.ReadDouble();();
right = BinaryFile.ReadDouble();();
top = BinaryFile.ReadDouble();();
partcount = bb0.getInt();
pointcount = bb0.getInt();
int[] parts = new int[partcount];
int[] partspos = new int[partcount];
double[] xpoints = new double[pointcount];
double[] ypoints = new double[pointcount];
double[] zpoints = new double[pointcount];
//firstly read out parts begin pos in file
for(int j = 0; j < partcount;j++){
parts[j]= bb0.getInt();
}
//shift them to be points count included in parts
if (partcount > 0)
partspos[0]=0;
int newpos=0;
for(int j = 0; j <= partcount-2;j++){
parts[j]= parts[j+1] - parts[j];
newpos+=parts[j];
partspos[j+1]=newpos;
}
parts[partcount-1]=pointcount-parts[partcount-1];
//read out coordinates
for(int j = 0 ; j < pointcount;j++){
x= BinaryFile.ReadDouble();();
y= BinaryFile.ReadDouble();();
xpoints[j] = x;
ypoints[j] = y;
zpoints[j] = 0;
}
if (pointcount>1){
MKGeoPolygon gl = new MKGeoPolygon(xpoints,ypoints,zpoints,parts,partspos,pointcount,partcount);
gl.envlope.left = left;
gl.envlope.right = right;
gl.envlope.top = top;
gl.envlope.bottom = bottom;
gl.objectID = i;
gl.objectUID = i;
geolayer.getDataContainer().add(gl);
}
}
break;
default :
// System.out.println(NotifyMessages.NO_SUCHTYPE);
return false;
}
}
catch(FileNotFoundException e){
return false;
}
catch(EOFException e2){
return false;
}
catch(IOException e1){
return false;
}
catch(Exception e){
return false;
}*/
return true;
}
public bool SaveShapeFile(CGDataAdapter.CGLocalGeoDataAdapter adapter)
{
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -