Index: includes/geo.api.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/geo/includes/geo.api.inc,v
retrieving revision 1.5
diff -u -p -r1.5 geo.api.inc
--- includes/geo.api.inc	21 Dec 2009 17:29:55 -0000	1.5
+++ includes/geo.api.inc	24 Dec 2009 05:45:51 -0000
@@ -368,17 +368,71 @@ function geo_value($input, $output_forma
       return $value['value'];
 
     case 'wkt':
+      if ($output_format == 'wkb') {
+        return db_result(db_query("SELECT GeomFromText('%s')", $input));
+      }
+      if ($output_format == 'array') {
+        return db_fetch_array(db_query("
+        SELECT
+          X(geom) as lon, 
+          Y(geom) as lat 
+        FROM (
+          SELECT GeomFromText('%s') as geom
+        ) as geomtable
+      ", $input));
+      }
       break;
 
     case 'array':
       if ($output_format == 'wkt') {
         return geo('wkt_from_point', $input['lat'], $input['lon']);
       }
+      if ($output_format == 'wkb') {
+      	// To get wkb, first get wkt, then convert.
+      	$wkt = geo_value($input, 'wkt', 'array');
+        return geo_value($wkt, 'wkb', 'wkt');
+      }
       break;
   }
 }
 
 /**
+ * Given a value and a gis type, detect the format
+ */
+function geo_detect($value, $gis_type) {
+	if (is_array($value) && $gis_type == 'point') {
+		return 'array';
+	}
+	if (is_string($value)) {
+		// A string could be wkt or wkb
+		
+		// Test for WKT
+		if (strtoupper(substr($value, 0, strlen($gis_type))) == strtoupper($gis_type)) {
+			return 'wkt';
+		}
+		
+		// Test for WKB
+		module_load_include('inc', 'geo', 'includes/geo.wkb');
+		// Put our data into memory so we can cruise around with fread.
+    $fp = fopen("php://memory", 'r+');
+    fputs($fp, $value);
+    fseek($fp, 0);
+
+    // Fetch the byte order (0 = Big Endian, 1 = Little Endian) and geo type.
+    $data = unpack('cbyte_order', fread($fp, 1));
+    $byte_order = $data['byte_order'];
+    $data = array_merge($data, unpack(($byte_order ? 'Vtype' : 'Ntype'), fread($fp, 4)));
+    
+    fclose ($fp);
+    
+    if (geo_wkb_types($data['type']) == $gis_type) {
+    	return 'wkb';
+		}
+		
+	}
+}
+
+/**
  * Determine which gis input formats are supported by a theme function.
  */
 function geo_theme_input($theme) {
Index: modules/geo_field/geo_field.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/geo/modules/geo_field/geo_field.module,v
retrieving revision 1.30
diff -u -p -r1.30 geo_field.module
--- modules/geo_field/geo_field.module	9 Dec 2009 17:34:03 -0000	1.30
+++ modules/geo_field/geo_field.module	24 Dec 2009 05:45:51 -0000
@@ -115,16 +115,19 @@ function geo_field($op, &$node, $field, 
     case 'presave':
       foreach ($items as $k => $item) {
         if(!geo_content_is_empty($item, $field)) {
+					
+					$format = geo_detect($item['geo'],$field['geo_type']);
 
-          // Convert to WKT (TODO we don't have direct-to-wkb functions yet!)
-          if ($gis_input) {
-            $wkt = geo_value($item['geo'], 'wkt', $gis_input);
+					if ($format != 'wkb') {
+						$items[$k]['geo'] = geo_value($item['geo'], 'wkb', $format);
+					}
+					else {
+						// The wkb format is not acceptable for insertion into the database,
+						// convert to wkt and back again.
+						// @@TODO: fix this.
+						$wkt = geo_value($item['geo'], 'wkt', $format);
+					  $items[$k]['geo'] = geo_value($item['geo'], 'wkb', 'wkt');
           }
-          else $wkt = $item['geo'];
-
-          // Convert the WKT to binary data before the insert. This allows the
-          // input to pass through the binary query substitutions.
-          $items[$k]['geo'] = db_result(db_query("SELECT GeomFromText('%s', %d)", $wkt, $field['srid']));
         }
       }
       return;
