地图函数结构.docx

上传人:b****4 文档编号:6198691 上传时间:2023-05-09 格式:DOCX 页数:15 大小:17.64KB
下载 相关 举报
地图函数结构.docx_第1页
第1页 / 共15页
地图函数结构.docx_第2页
第2页 / 共15页
地图函数结构.docx_第3页
第3页 / 共15页
地图函数结构.docx_第4页
第4页 / 共15页
地图函数结构.docx_第5页
第5页 / 共15页
地图函数结构.docx_第6页
第6页 / 共15页
地图函数结构.docx_第7页
第7页 / 共15页
地图函数结构.docx_第8页
第8页 / 共15页
地图函数结构.docx_第9页
第9页 / 共15页
地图函数结构.docx_第10页
第10页 / 共15页
地图函数结构.docx_第11页
第11页 / 共15页
地图函数结构.docx_第12页
第12页 / 共15页
地图函数结构.docx_第13页
第13页 / 共15页
地图函数结构.docx_第14页
第14页 / 共15页
地图函数结构.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

地图函数结构.docx

《地图函数结构.docx》由会员分享,可在线阅读,更多相关《地图函数结构.docx(15页珍藏版)》请在冰点文库上搜索。

地图函数结构.docx

地图函数结构

地图函数结构

//读折线函数

voidGetPolyLine()

{

Map_PolyLine*mappolyline;

QGraphicsLineItem*line;

//intparts;//线段数量

intvertexs;//顶点数

doublelong;

doublelat;

charcharTemp;

QListlongs;//经度集

QListlats;//纬度集

intpenwidth;//线宽

intpenpattern;//风格

intpencolor;//颜色

QPenpen;//画笔

longs.clear();//先将经度链表清空

lats.clear();//清空纬度链表

QFilemapFile("road.mif");

QStringStrTemp="";

intok=mapFile.open(QIODevice:

:

ReadOnly);

if(ok)

{

QTextStreamt(&mapFile);

while(StrTemp!

="Data")

{

t>>StrTemp;

}

while(!

t.atEnd())

{

while(StrTemp!

="Pline")

t>>StrTemp;

t>>vertexs;//读线段段数

//qDebug()<<"vertexs="<

for(inti=0;i

{

t>>long>>lat;

longs.append(long);

lats.append(lat);

}

t>>charTemp;

while(charTemp!

='(')

t>>charTemp;

t>>penwidth>>charTemp>>penpattern>>charTemp>>pencolor>>charTemp;//读线宽,风格,颜色。

pen.setWidth(penwidth);//设线宽

pen.setStyle(Qt:

:

SolidLine);//设画线风格为实线

pen.setColor(pencolor);//设画笔颜色

if(longs.count()>0&&(longs.count()==lats.count()))

{

mappolyline=newMap_PolyLine();

}

else

{

return;//函数结束,不执行后面的语句

}

for(i=0;i

{

line=newQGraphicsLineItem();

line->setLine(QLineF(convertCoord(longs.at(i),lats.at(i)),convertCoord(longs.at(i+1),lats.at(i+1))));

//line->setLine(QLineF(convertCoord(lats.at(i),longs.at(i)),convertCoord(lats.at(i+1),longs.at(i+1))));

line->setPen(pen);

mappolyline->mapPolyLine.append(line);

}

mapPolyLines.append(mappolyline);//添加一个折线对象进折线链表

}

}

}

 

//读区域函数

voidMap_Layer:

:

GetRegion(mitab_featurefeature,QStringList&fields)

{

Map_Region*region;//定义指向区域类的指针

QPolygonF*polygon;//

Map_Field*field;//定义指向结构体的指针

intparts;//线段数量

intvertexs;//顶点数量

doublelong;//暂存经度

doublelat;

charcharTemp;

QListlongs;//经度集

QListlats;//纬度集

intpencolor;

intpenpattern;

intpenwidth;

QPenpen;

intbrushcolor;//区域填充颜色

intbrushpattern;//填充风格

//QBrushbrush(QColor(Qt:

:

black));//这里比较ds奇怪,必须这样,后面的setColor才起作用

 

QFilemapFile("block.mif");

QStringStrTemp="";

intok=mapFile.open(QIODevice:

:

ReadOnly);

if(ok)

{

QTextStreamt(&mapFile);

while(StrTemp!

="Data")

{

t>>StrTemp;

}

while(!

t.atEnd())

{

while(StrTemp!

="Region1")

t>>StrTemp;

t>>vertexs;//读区域顶点数量

//qDebug()<<"vertexs="<

for(inti=0;i

{

t>>long>>lat;

longs.append(long);

lats.append(lat);

}

t>>charTemp;

while(charTemp!

='(')

t>>charTemp;

t>>penwidth>>charTemp>>penpattern>>charTemp>>pencolor>>charTemp;//读线宽,风格,颜色。

pen.setWidth(penwidth);//设线宽

pen.setStyle(Qt:

:

SolidLine);//设画线风格为实线

pen.setColor(pencolor);//设画笔颜色

if(longs.count()>0&&(longs.count()==lats.count()))

{

mappolyline=newMap_PolyLine();

}

else

{

return;//函数结束,不执行后面的语句

}

for(i=0;i

{

line=newQGraphicsLineItem();

line->setLine(QLineF(convertCoord(longs.at(i),lats.at(i)),convertCoord(longs.at(i+1),lats.at(i+1))));

//line->setLine(QLineF(convertCoord(lats.at(i),longs.at(i)),convertCoord(lats.at(i+1),longs.at(i+1))));

line->setPen(pen);

mappolyline->mapPolyLine.append(line);

}

mapPolyLines.append(mappolyline);//添加一个折线对象进折线链表

}

}

//设画笔颜色,风格为实线,线宽

pen.setColor(pencolor);

pen.setStyle(Qt:

:

SolidLine);

pen.setWidth(penwidth);

//pen.setBrush(QBrush(QColor(Qt:

:

blue)));

/*if(penpattern==2)

{

pen.setStyle(Qt:

:

SolidLine);

}

else

{

pen.setStyle(Qt:

:

DashLine);

}*/

brushcolor=mitab_c_get_brush_fgcolor(feature);//读取填充颜色

//qDebug()<<"fgbrushcolor="<

brushpattern=mitab_c_get_brush_pattern(feature);

//qDebug()<<"brushpattern="<

brush.setColor(QColor(brushcolor));

region=newMap_Region();

for(i=0;i

{

field=newMap_Field;//开地图区域结构体保存区域名,区域填充

field->fieldName=fields.at(i);//读区域名

field->fieldContent=mitab_c_get_field_as_string(feature,i);//

qDebug()<<"fieldNameis"<fieldName<<"fieldcontentis"<fieldContent;

region->mapFields.append(field);

if(field->fieldName=="Name")

{

region->regionName->setPlainText(field->fieldContent);

}

}

parts=mitab_c_get_parts(feature);//读对象折线段数量

//qDebug()<<"parts="<

longs.clear();

lats.clear();

for(i=0;i

{

vertexs=mitab_c_get_vertex_count(feature,i);//读顶点数

//qDebug()<<"vertexs="<

for(j=0;j

{

longs.append(mitab_c_get_vertex_x(feature,i,j));

lats.append(mitab_c_get_vertex_y(feature,i,j));

}

}

if(longs.count()>0&&(longs.count()==lats.count()))

{

//region=newMap_Region();

polygon=newQPolygonF();

}

else

{

return;

}

//qDebug()<<"count="<

for(i=0;i

{

polygon->append(QPointF(convertCoord(longs.at(i),lats.at(i))));

}

if(polygon->count()>0)

{

//qDebug()<<"X="<boundingRect().center().x()<<"Y="<boundingRect().center().y();

//region->regionName->setX(polygon->boundingRect().center().x());

//region->regionName->setY(polygon->boundingRect().center().y());

}

region->mapPolygon->setPen(pen);

region->mapPolygon->setBrush(brush);

region->mapPolygon->setPolygon(*polygon);

mapRegions.append(region);

}

 

//另外的读取方法(一个图元的显示)

if(graphicsName=="Region")

{

laton>>count>>count;//记录区域顶点数

for(inti=0;i

{

laton>>x>>y;//x存放经度,y存放纬度

point=newQPointF(((x-x1)/wx)*w-w/2,((y1-y)/hy)*h-h/2);

//把经纬度转为QGraphicsSense坐标后存到point中

pointfRegion<<*point;//把转换后的点存进pointfRegion容器中

}

pPolygonF=newQPolygonF(pointfRegion);//创建多边形

pPolygonItem=newQGraphicsPolygonItem(*pPolygonF);//创建多边形图元

if(graphicsAttribute=="Pen")//一个图元的点描述后就是该图元的边界画笔,用Pen表示

{

latlon>>penColor;

sColor.append(penColor);

pen.setColor(QColor(sColor.section(",",2,2),remove(Qchar(')'),Qt:

:

CaseInsensitive).toDouble()));//获取画笔颜色

pPolygonItem->setPen(pen);//设置图元边界颜色

}

if(graphicsAttribute=="Brush")//该图元的边界画笔描述完,继续用Brush表示填充颜色

{

latlon>>brushColor;

sColor.append(brushColor);

brush.setColor(sColor.section(",",1,1).toDouble);

}

pPolygonItem->setBrush(brush);//对图元进行颜色填充

scene->addIten(pPolygonItem);//最后把图元添加到画布上

 

}

 

classMapTextItem

{

public:

MapTextItem(QStringstr);

MapTextItem();

virtual~MapTextItem(void);

QGraphicsTextItem*mapTextItem;//存放当前QGraphicsTextItem的地址

MapTextItem*nextTextItem;//存放下一个QgraphicsTextItem的地址

};

通过对数据的处理而获取所有地图中文本图元。

当检测到一个图元是就添加到链表的末端,直到没有为止。

if(graphicsName=="Text")

{

latlon>>graphicsName;//获取文本信息

latlon>>x>>y;

mapText=newMapTextItem(graphicsName);

mapText->mapTextItem->setPos(((x-x1)/wx)*w-w/2,((y1-y)/hy)*h-h/2);

scene->addItem(mapText->mapTextItem);//在地图上面显示

mapText->nextTextItem=mapTextItem->nextTextItem;

mapTextItem->nextTextItem=mapText;//连接到链表中

}

 

voidreadMap()

{

QFilemapFile("road.mif");

QStringStrTemp="null";

intok=mapFile.open(QIODevice:

:

ReadOnly);

if(ok)

{

QTextStreamt(&mapFile);

if(!

t.atEnd())

{

while(StrTemp!

="Data")

{

t>>StrTemp;

}

while()

t>>x1>>y1>>x2>>y2;

}

}

//

map.load(mapName);

if(map.isNull())

printf("mapisnull");

}

 

平面点a(x1,y1),b(x2,y2)

距离l=sqrt((x1-x2)(平方)+(y1-y2)(平方))

 

typedefstruct

{

intId1;

QListoverIds;

}overlapPoints;

QListoverPointList;

overlapPointspointTemp;

for(inti=0;i

{

pointTemp.Id1=nodeList.at(i).nodeId;

for(intj=i+1;j

{

if(nodeList.at(j).latlon.longitude==nodeList.at(i).latlon.longitude&&

nodeList.at(j).latlon.latitude==nodeList.at(i).latlon.latitude)

{

inttemp=nodeList.at(j).nodeId;

pointTemp.overIds.append(temp);

nodeList.removeAt(j);

j--;

}

}

if(pointTemp.overIds.count()>=1)

overPointList.append(pointTemp);

}

for(inti=0;i

{

intk;

k=nodeList.at(i).nodeId;

nodeList.at(i).nodeId=i;

for(intj=0;j

{

if(overPointList.at(j).Id1==k)

{

if(roadList.at(k/2).startId==k)

roadList.at(k/2).startId=i;

else

roadList.at(k/2).endId=i;

for(intm=0;m

{

inttemp=overPointList.at(j).overIds.at(m);

if(roadList.at(temp/2).startId==temp)

roadList.at(temp/2).startId=i;

else

roadList.at(temp/2).endId=i;

}

overPointList.removeAt(j);

}

}

}

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2