[cairo-commit] roadster/src db.c, 1.10, 1.11 db.h, 1.5, 1.6 map.c, 1.12, 1.13 search_road.c, 1.10, 1.11

Ian McIntosh commit at pdx.freedesktop.org
Tue Mar 1 22:25:50 PST 2005


Committed by: ian

Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv21986/src

Modified Files:
	db.c db.h map.c search_road.c 
Log Message:
	* search_road.c:
	* map.c:
	* db.c: Switch to binary format for MySQL geometry results.


Index: db.c
===================================================================
RCS file: /cvs/cairo/roadster/src/db.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- db.c	1 Mar 2005 19:48:21 -0000	1.10
+++ db.c	2 Mar 2005 06:25:48 -0000	1.11
@@ -506,49 +506,33 @@
 	}	
 }
 
-void db_parse_pointstring(const gchar* pszText, pointstring_t* pPointString, gboolean (*callback_get_point)(mappoint_t**))
+#define WKB_POINT                  1	// only two we care about
+#define WKB_LINESTRING             2
+
+void db_parse_wkb_pointstring(const gint8* data, pointstring_t* pPointString, gboolean (*callback_get_point)(mappoint_t**))
 {
-	// parse string and add points to the string
-	const gchar* p = pszText;
-	if(p[0] == 'L') { //g_str_has_prefix(p, "LINESTRING")) {
-		// format is "LINESTRING(1.2345 5.4321, 10 10, 20 20)"
-		mappoint_t* pPoint;
+	g_assert(sizeof(double) == 8);	// mysql gives us 8 bytes per point
 
-		p += (11); 	// move past "LINESTRING("
+	gint nByteOrder = *data++;	// first byte tells us the byte order
+	g_assert(nByteOrder == 1);
 
-		while(TRUE) {
-			// g_print("reading a point...\n");
-			pPoint = NULL;
-			if(!callback_get_point(&pPoint)) return;
+	gint nGeometryType = *((gint32*)data)++;
+	g_assert(nGeometryType == WKB_LINESTRING);
 
-			// read in latitude
-			pPoint->m_fLatitude = g_ascii_strtod(p, (gchar**)&p);
+	// next 4 bytes is the point count
+	gint nNumPoints = *((gint32*)data)++;	// NOTE for later: this field doesn't exist for type POINT
 
-			// space between coordinates
-			g_return_if_fail(*p == ' ');
-			p++;
+	while(nNumPoints > 0) {
+		// g_print("reading a point...\n");
+		mappoint_t* pPoint = NULL;
+		if(!callback_get_point(&pPoint)) return;
 
-			// read in longitude
-			pPoint->m_fLongitude = g_ascii_strtod(p, (gchar**)&p);
-			
-			// g_print("got (%f,%f)\n", pPoint->m_fLatitude, pPoint->m_fLongitude);
-			
-			// add point to the list
-			g_ptr_array_add(pPointString->m_pPointsArray, pPoint);
+		pPoint->m_fLatitude = *((double*)data)++;
+		pPoint->m_fLongitude = *((double*)data)++;
 
-			if(*p == ',') {
-				p++;
+		g_ptr_array_add(pPointString->m_pPointsArray, pPoint);
 
-				// after this, we're ready to read in next point, so loop...
-				// g_print("looping for another!...\n");
-			}
-			else {
-				break;
-			}
-		}
-	}
-	else {
-		g_assert_not_reached();
+		nNumPoints--;
 	}
 }
 
@@ -830,6 +814,52 @@
 		return FALSE;
 	}
 }
+
+void db_parse_pointstring(const gchar* pszText, pointstring_t* pPointString, gboolean (*callback_get_point)(mappoint_t**))
+{
+	// parse string and add points to the string
+	const gchar* p = pszText;
+	if(p[0] == 'L') { //g_str_has_prefix(p, "LINESTRING")) {
+		// format is "LINESTRING(1.2345 5.4321, 10 10, 20 20)"
+		mappoint_t* pPoint;
+
+		p += (11); 	// move past "LINESTRING("
+
+		while(TRUE) {
+			// g_print("reading a point...\n");
+			pPoint = NULL;
+			if(!callback_get_point(&pPoint)) return;
+
+			// read in latitude
+			pPoint->m_fLatitude = g_ascii_strtod(p, (gchar**)&p);
+
+			// space between coordinates
+			g_return_if_fail(*p == ' ');
+			p++;
+
+			// read in longitude
+			pPoint->m_fLongitude = g_ascii_strtod(p, (gchar**)&p);
+			
+			// g_print("got (%f,%f)\n", pPoint->m_fLatitude, pPoint->m_fLongitude);
+			
+			// add point to the list
+			g_ptr_array_add(pPointString->m_pPointsArray, pPoint);
+
+			if(*p == ',') {
+				p++;
+
+				// after this, we're ready to read in next point, so loop...
+				// g_print("looping for another!...\n");
+			}
+			else {
+				break;
+			}
+		}
+	}
+	else {
+		g_assert_not_reached();
+	}
+}
 */
 #endif
 

Index: db.h
===================================================================
RCS file: /cvs/cairo/roadster/src/db.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- db.h	1 Mar 2005 19:48:21 -0000	1.5
+++ db.h	2 Mar 2005 06:25:48 -0000	1.6
@@ -77,7 +77,8 @@
 void db_free_escaped_string(gchar* pszString);
 
 void db_parse_point(const gchar* pszText, mappoint_t* pPoint);
-void db_parse_pointstring(const gchar* pszText, pointstring_t* pPointString, gboolean (*callback_get_point)(mappoint_t**));
+//void db_parse_pointstring(const gchar* pszText, pointstring_t* pPointString, gboolean (*callback_get_point)(mappoint_t**));
+void db_parse_wkb_pointstring(const gint8* data, pointstring_t* pPointString, gboolean (*callback_get_point)(mappoint_t**));
 
 void db_enable_keys(void);
 void db_disable_keys(void);

Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- map.c	1 Mar 2005 19:48:21 -0000	1.12
+++ map.c	2 Mar 2005 06:25:48 -0000	1.13
@@ -988,10 +988,16 @@
 
 	// Raise the tolerance way up for thin lines
 	gint nCapStyle = pSubLayerStyle->m_nCapStyle;
+	
+	// XXX: HACK
+//	nCapStyle = CAIRO_LINE_CAP_SQUARE;
 
 	gdouble fTolerance;
-	if(fLineWidth >= 6.0) {
-		fTolerance = 0.6;
+	if(fLineWidth > 12.0) {	// huge line, low tolerance
+		fTolerance = 0.55;
+	}
+	else if(fLineWidth >= 6.0) {	// medium line, medium tolerance
+		fTolerance = 1.0;
 	}
 	else {
 		if(nCapStyle == CAIRO_LINE_CAP_ROUND) {
@@ -1138,7 +1144,7 @@
 
 	// generate SQL
 	gchar* pszSQL = g_strdup_printf(
-		"SELECT Road.ID, Road.TypeID, AsText(Road.Coordinates), RoadName.Name, RoadName.SuffixID"
+		"SELECT Road.ID, Road.TypeID, AsBinary(Road.Coordinates), RoadName.Name, RoadName.SuffixID"
 		" FROM Road "
 		" LEFT JOIN Road_RoadName ON (Road.ID=Road_RoadName.RoadID)"
 		" LEFT JOIN RoadName ON (Road_RoadName.RoadNameID=RoadName.ID)"
@@ -1185,7 +1191,7 @@
 				g_warning("out of memory loading pointstrings\n");
 				continue;
 			}
-			db_parse_pointstring(aRow[2], pNewPointString, point_alloc);
+			db_parse_wkb_pointstring(aRow[2], pNewPointString, point_alloc);
 
 			// Build name by adding suffix, if one is present
 			gchar azFullName[100] = "";

Index: search_road.c
===================================================================
RCS file: /cvs/cairo/roadster/src/search_road.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- search_road.c	1 Mar 2005 19:48:21 -0000	1.10
+++ search_road.c	2 Mar 2005 06:25:48 -0000	1.11
@@ -319,7 +319,7 @@
 	}
 
 	g_snprintf(azQuery, MAX_QUERY,
-		"SELECT Road.ID, RoadName.Name, RoadName.SuffixID, AsText(Road.Coordinates), Road.AddressLeftStart, Road.AddressLeftEnd, Road.AddressRightStart, Road.AddressRightEnd, CityLeft.Name, CityRight.Name"
+		"SELECT Road.ID, RoadName.Name, RoadName.SuffixID, AsBinary(Road.Coordinates), Road.AddressLeftStart, Road.AddressLeftEnd, Road.AddressRightStart, Road.AddressRightEnd, CityLeft.Name, CityRight.Name"
 		", StateLeft.Code, StateRight.Code, Road.ZIPCodeLeft, Road.ZIPCodeRight"
 		" FROM RoadName"
 		" LEFT JOIN Road_RoadName ON (RoadName.ID=Road_RoadName.RoadNameID)"
@@ -390,7 +390,8 @@
 			if(nCount <= SEARCH_RESULT_COUNT_LIMIT) {
 				pointstring_t* pPointString = NULL;
 				pointstring_alloc(&pPointString);
-				db_parse_pointstring(aRow[3], pPointString, point_alloc);
+				
+				db_parse_wkb_pointstring(aRow[3], pPointString, point_alloc);
 
 //	g_print("raw: %s\n", aRow[3]);
 				search_road_filter_result(aRow[1], pRoadSearch->m_nNumber, atoi(aRow[2]), atoi(aRow[4]), atoi(aRow[5]), atoi(aRow[6]), atoi(aRow[7]), aRow[8], aRow[9], aRow[10], aRow[11], aRow[12], aRow[13], pPointString);




More information about the cairo-commit mailing list