示例#1
0
文件: transform.c 项目: albertz/navit
struct map_selection *
transform_get_selection(struct transformation *this_, enum projection pro, int order)
{

	struct map_selection *ret,*curri,*curro;
	struct coord_geo g;
	
	ret=map_selection_dup(this_->map_sel);
	curri=this_->map_sel;
	curro=ret;
	while (curri) {
		if (this_->pro != pro) {
			transform_to_geo(this_->pro, &curri->u.c_rect.lu, &g);
			transform_from_geo(pro, &g, &curro->u.c_rect.lu);
			dbg(1,"%f,%f", g.lat, g.lng);
			transform_to_geo(this_->pro, &curri->u.c_rect.rl, &g);
			transform_from_geo(pro, &g, &curro->u.c_rect.rl);
			dbg(1,": - %f,%f\n", g.lat, g.lng);
		}
		dbg(1,"transform rect for %d is %d,%d - %d,%d\n", pro, curro->u.c_rect.lu.x, curro->u.c_rect.lu.y, curro->u.c_rect.rl.x, curro->u.c_rect.rl.y);
		curro->order+=order;
#if 0
		curro->u.c_rect.lu.x-=500;
		curro->u.c_rect.lu.y+=500;
		curro->u.c_rect.rl.x+=500;
		curro->u.c_rect.rl.y-=500;
#endif
		curro->range=item_range_all;
		curri=curri->next;
		curro=curro->next;
	}
	return ret;
}
示例#2
0
static int
textfile_coord_get(void *priv_data, struct coord *c, int count)
{
	double lat,lng;
	struct coord_geo cg;
	struct map_rect_priv *mr=priv_data;
	int ret=0;
	if (debug)
		printf("textfile_coord_get %d\n",count);
	while (count--) {
		if (contains_coord(mr->line) && mr->f && !feof(mr->f) && (!mr->item.id_hi || !mr->eoc)) {
			parse_line(mr);
			lat=mr->lat;
			lng=mr->lng;
			cg.lat=floor(lat/100);
			lat-=cg.lat*100;
			cg.lat+=lat/60;

			cg.lng=floor(lng/100);
			lng-=cg.lng*100;
			cg.lng+=lng/60;

			transform_from_geo(projection_mg, &cg, c);
			c++;
			ret++;		
			get_line(mr);
			if (mr->item.id_hi)
				mr->eoc=1;
		} else {
			break;
		}
	}
	return ret;
}
示例#3
0
文件: transform.c 项目: albertz/navit
void
transform_from_to(struct coord *cfrom, enum projection from, struct coord *cto, enum projection to)
{
	struct coord_geo g;
	transform_to_geo(from, cfrom, &g);
	transform_from_geo(to, &g, cto);
}
示例#4
0
文件: transform.c 项目: albertz/navit
void
transform_from_to_count(struct coord *cfrom, enum projection from, struct coord *cto, enum projection to, int count)
{
	struct coord_geo g;
	int i;

	for (i = 0 ; i < count ; i++) {
		transform_to_geo(from, cfrom, &g);
		transform_from_geo(to, &g, cto);
		cfrom++;
		cto++;
	}
}
示例#5
0
文件: navit.c 项目: justinzane/navit
static void
navit_projection_set(struct menu *menu, void *this__p, void *pro_p)
{
	struct navit *this_=this__p;
	enum projection pro=(enum projection) pro_p;
	struct coord_geo g;
	struct coord *c;

	c=transform_center(this_->trans);
	transform_to_geo(transform_get_projection(this_->trans), c, &g);
	transform_set_projection(this_->trans, pro);
	transform_from_geo(pro, &g, c);
	navit_draw(this_);
}
示例#6
0
文件: shapefile.c 项目: PDXostc/navit
static void
shapefile_coord(struct map_rect_priv *mr, int idx, struct coord *c)
{
	SHPObject *psShape=mr->psShape;
	struct coord cs;
	struct coord_geo g;

	if (!mr->m->pro) {
		g.lng=psShape->padfX[idx]+mr->m->offset.x;
		g.lat=psShape->padfY[idx]+mr->m->offset.y;
		transform_from_geo(projection_mg, &g, c);
	} else {
		cs.x=psShape->padfX[idx]+mr->m->offset.x;
		cs.y=psShape->padfY[idx]+mr->m->offset.y;
		transform_from_to(&cs, mr->m->pro, c, projection_mg);
	}
}
示例#7
0
文件: coord.c 项目: justinzane/navit
int
coord_parse(const char *c_str, enum projection pro, struct coord *c_ret)
{
	int debug=0;
	char *proj=NULL,*s,*co;
	const char *str=c_str;
	int args,ret = 0;
	struct coord_geo g;
	struct coord c;
	enum projection str_pro=projection_none;

	dbg(1,"enter('%s',%d,%p)\n", c_str, pro, c_ret);
	s=strchr(str,' ');
	co=strchr(str,':');
	if (co && co < s) {
		proj=malloc(co-str+1);
		strncpy(proj, str, co-str);
		proj[co-str]='\0';
		dbg(1,"projection=%s\n", proj);
		str=co+1;
		s=strchr(str,' ');
		if (!strcmp(proj, "mg"))
			str_pro = projection_mg;
		else if (!strcmp(proj, "garmin"))
			str_pro = projection_garmin;
		else if (!strcmp(proj, "geo"))
			str_pro = projection_none;
		else {
			dbg(0, "Unknown projection: %s\n", proj);
			goto out;
		}
	}
	if (! s) {
		ret=0;
		goto out;
	}
	while (*s == ' ') {
		s++;
	}
	if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) {
		args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
		if (args < 2)
			goto out;
		dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret);
		dbg(1,"rest='%s'\n", str+ret);

		if (str_pro == projection_none) 
			str_pro=projection_mg;
		if (str_pro != pro) {
			transform_to_geo(str_pro, &c, &g);
			transform_from_geo(pro, &g, &c);
		}
		*c_ret=c;
	} else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') {
		double lng, lat;
		char ns, ew;
		dbg(1,"str='%s'\n", str);
		args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret);
		dbg(1,"args=%d\n", args);
		dbg(1,"lat=%f %c lon=%f %c\n", lat, ns, lng, ew);
		if (args < 4)
			goto out;
		dbg(1,"projection=%d str_pro=%d projection_none=%d\n", pro, str_pro, projection_none);
		if (str_pro == projection_none) {
			g.lat=floor(lat/100);
			lat-=g.lat*100;
			g.lat+=lat/60;
			g.lng=floor(lng/100);
			lng-=g.lng*100;
			g.lng+=lng/60;
			if (ns == 's' || ns == 'S')
				g.lat=-g.lat;
			if (ew == 'w' || ew == 'W')
				g.lng=-g.lng;
			dbg(1,"transform_from_geo(%f,%f)",g.lat,g.lng);
			transform_from_geo(pro, &g, c_ret);
			dbg(1,"result 0x%x,0x%x\n", c_ret->x,c_ret->y);
		}
		dbg(3,"str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, lat, ew, ret);
		dbg(3,"rest='%s'\n", str+ret);
	} else {
		double lng, lat;
		args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret);
		if (args < 2)
			goto out;
		dbg(1,"str='%s' x=%f y=%f  c=%d\n", str, lng, lat, ret);
		dbg(1,"rest='%s'\n", str+ret);
		g.lng=lng;
		g.lat=lat;
		transform_from_geo(pro, &g, c_ret);
	}
	if (debug)
		printf("rest='%s'\n", str+ret);
	ret+=str-c_str;
	if (debug) {
		printf("args=%d\n", args);
		printf("ret=%d delta=%d ret_str='%s'\n", ret, str-c_str, c_str+ret);
	}
out:
	if (proj)
		free(proj);
	return ret;
}
示例#8
0
文件: transform.c 项目: albertz/navit
int
transform(struct transformation *t, enum projection pro, struct coord *c, struct point *p, int count, int mindist, int width, int *width_return)
{
	struct coord c1;
	int xcn, ycn; 
	struct coord_geo g;
	int xc, yc, zc=0, xco=0, yco=0, zco=0;
	int xm,ym,zct;
	int zlimit=t->znear;
	int visible, visibleo=-1;
	int i,j = 0,k=0;
	dbg(1,"count=%d\n", count);
	for (i=0; i < count; i++) {
		if (pro == t->pro) {
			xc=c[i].x;
			yc=c[i].y;
		} else {
			transform_to_geo(pro, &c[i], &g);
			transform_from_geo(t->pro, &g, &c1);
			xc=c1.x;
			yc=c1.y;
		}
		if (i != 0 && i != count-1 && mindist) {
			if (xc > c[k].x-mindist && xc < c[k].x+mindist && yc > c[k].y-mindist && yc < c[k].y+mindist &&
				(c[i+1].x != c[0].x || c[i+1].y != c[0].y))
				continue;
			k=i;
		}
		xm=xc;
		ym=yc;
//		dbg(2,"0x%x, 0x%x - 0x%x,0x%x contains 0x%x,0x%x\n", t->r.lu.x, t->r.lu.y, t->r.rl.x, t->r.rl.y, c->x, c->y);
//		ret=coord_rect_contains(&t->r, c);
		xc-=t->map_center.x;
		yc-=t->map_center.y;
		xc >>= t->scale_shift;
		yc >>= t->scale_shift;
		xm=xc;
		ym=yc;

		xcn=xc*t->m00+yc*t->m01+HOG(*t)*t->m02;
		ycn=xc*t->m10+yc*t->m11+HOG(*t)*t->m12;

		if (t->ddd) {
			zc=(xc*t->m20+yc*t->m21+HOG(*t)*t->m22);
			zct=zc;
			zc+=t->offz << POST_SHIFT;
			dbg(1,"zc=%d\n", zc);
			dbg(1,"zc(%d)=xc(%d)*m20(%d)+yc(%d)*m21(%d)\n", (xc*t->m20+yc*t->m21), xc, t->m20, yc, t->m21);
			/* visibility */
			visible=(zc < zlimit ? 0:1);
			dbg(1,"visible=%d old %d\n", visible, visibleo);
			if (visible != visibleo && visibleo != -1) { 
				dbg(1,"clipping (%d,%d,%d)-(%d,%d,%d) (%d,%d,%d)\n", xcn, ycn, zc, xco, yco, zco, xco-xcn, yco-ycn, zco-zc);
				if (zco != zc) {
					xcn=xcn+(long long)(xco-xcn)*(zlimit-zc)/(zco-zc);
					ycn=ycn+(long long)(yco-ycn)*(zlimit-zc)/(zco-zc);
				}
				dbg(1,"result (%d,%d,%d) * %d / %d\n", xcn,ycn,zc,zlimit-zc,zco-zc);
				zc=zlimit;
				xco=xcn;
				yco=ycn;
				zco=zc;
				if (visible)
					i--;
				visibleo=visible;
			} else {
				xco=xcn;
				yco=ycn;
				zco=zc;
				visibleo=visible;
				if (! visible)
					continue;
			}
			dbg(1,"zc=%d\n", zc);
			dbg(1,"xcn %d ycn %d\n", xcn, ycn);
			dbg(1,"%d,%d %d\n",xc,yc,zc);
#if 0
			dbg(0,"%d/%d=%d %d/%d=%d\n",xcn,xc,xcn/xc,ycn,yc,ycn/yc);
#endif
#if 1
			xc=(long long)xcn*t->xscale/zc;
			yc=(long long)ycn*t->yscale/zc;
#else
			xc=xcn/(1000+zc);
			yc=ycn/(1000+zc);
#endif
#if 0
			dbg(1,"%d,%d %d\n",xc,yc,zc);
#endif
		} else {
			xc=xcn;
			yc=ycn;
			xc>>=POST_SHIFT;
			yc>>=POST_SHIFT;
		}
		xc+=t->offx;
		yc+=t->offy;
		p[j].x=xc;
		p[j].y=yc;
		if (width_return) {
			if (t->ddd) 
				width_return[j]=width*t->wscale/zc;
			else 
				width_return[j]=width;
		}
		j++;
	}
	return j;
}
示例#9
0
文件: coord.c 项目: justinzane/navit
int
coord_parse(const char *c_str, enum projection pro, struct coord *c_ret)
{
	int debug=0;
	char *proj=NULL,*s,*co;
	const char *str=c_str;
	int args,ret;
	struct coord_geo g;
	struct coord c;
	enum projection str_pro=projection_none;

	dbg(1,"enter('%s',%d,%p)\n", c_str, pro, c_ret);
	s=index(str,' ');
	co=index(str,':');
	if (co && co < s) {
		proj=malloc(co-str+1);
		strncpy(proj, str, co-str);
		proj[co-str]='\0';
		dbg(1,"projection=%s\n", proj);
		str=co+1;
		s=index(str,' ');
	}
	while (*s == ' ') {
		s++;
	}
	if (!strncmp(str, "0x", 2) || !strncmp(str,"-0x", 3)) {
		args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
		if (args < 2)
			return 0;
		dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret);
		dbg(1,"rest='%s'\n", str+ret);

		if (str_pro == projection_none) 
			str_pro=projection_mg;
		if (str_pro == projection_mg) {
			*c_ret=c;
		} else {
			printf("help\n");
		}
	} else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') {
		dbg(1,"str='%s'\n", str);
		double lng, lat;
		char ns, ew;
		args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret);
		if (args < 4)
			return 0;
		if (str_pro == projection_none) {
			g.lat=floor(lat/100);
			lat-=g.lat*100;
			g.lat+=lat/60;
			g.lng=floor(lng/100);
			lng-=g.lng*100;
			g.lng+=lng/60;
			transform_from_geo(pro, &g, c_ret);
		}
		if (debug) {
			printf("str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, lat, ew, ret);
			printf("rest='%s'\n", str+ret);
		}
	} else {
		double lng, lat;
		args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret);
		if (args < 2)
			return 0;
		printf("str='%s' x=%f y=%f  c=%d\n", str, lng, lat, ret);
		printf("rest='%s'\n", str+ret);
	}
	if (debug)
		printf("rest='%s'\n", str+ret);
	ret+=str-c_str;
	if (debug) {
		printf("args=%d\n", args);
		printf("ret=%d delta=%d ret_str='%s'\n", ret, str-c_str, c_str+ret);
	}
	if (proj)
		free(proj);
	return ret;
}