Forewarning: given the amout of memory you are reporting on your system I suppose you are using a 64 bit build of Windows. If not this solution does not apply.
The memory limit for all 32 bit applications on Windows (regardless of the Windows version, so it is true also for 64 bit Windows) is 2GB.
You might be hitting that limit, to confirm run ogr2ogr and check memory usage with task manager.
If the problem is indeed due to a memory issue you can do two things:
build yourself a 64 bit version of GDAL (I could not find readily avail binaries)
patch ogr2ogr.exe with this tool: http://ntcore.com/4gb_patch.php. After patching (make a backup copy of course) the binary should be available to address a grandtotal 4GB
Unfortunately, OGR sees the KML file as having 247 layers (ogrinfo doc.kml
), which is why you see the mess.
I would do a direct KML -> PostGIS conversion. You can keep a clean PostGIS DB by using a schema to contain the mess temporarily. From your SQL:
CREATE SCHEMA import;
Now from your shell (I'm using OSGeo4W Shell):
$ ogr2ogr -append -f PostgreSQL PG:"dbname='your_db' user='postgres' password='secret'" \
doc.kml -lco SCHEMA=import -lco EXTRACT_SCHEMA_FROM_LAYER_NAME=NO \
-lco OVERWRITE=YES -lco LAUNDER=NO
(No errors!)
Next, you need to stack your tables into one table in the public schema (assuming you have at least PostgreSQL 9.0 for the DO):
-- Create new table for all features
CREATE TABLE ice_rinks (gid serial PRIMARY KEY);
SELECT AddGeometryColumn('public', 'ice_rinks', 'geom', 4326, 'POINT', 3);
ALTER TABLE ice_rinks ADD COLUMN division text NOT NULL;
ALTER TABLE ice_rinks ADD COLUMN name text;
ALTER TABLE ice_rinks ADD COLUMN description text;
-- Combine them
DO $$DECLARE r record;
BEGIN
FOR r IN (SELECT relname, trim(relname) AS division
FROM pg_class c
JOIN pg_namespace n ON n.oid=c.relnamespace
WHERE n.nspname='import' AND relkind='r'
ORDER BY trim(relname))
LOOP
EXECUTE 'INSERT INTO ice_rinks(geom, division, "name", description) ' ||
'SELECT wkb_geometry, ' || quote_literal(r.division) || ', "Name", "Description" ' ||
'FROM import.' || quote_ident(r.relname) || ' ORDER BY ogc_fid';
END LOOP;
END$$;
I have 1265 features .. hopefully they're all there.
Lastly, cleanup. You can remove your import schema if the data looks good:
DROP SCHEMA import CASCADE;
And if you are using PostGIS 1.5 or prior:
DELETE FROM geometry_columns WHERE f_table_schema='import';
Best Answer
The utility programs included in OGR (OGR2OGR) will not do this directly, but it will be very easy to use OGR to accomplish this.
You would need to write a script/program in any of the languages supported by OGR. You could just have it open the shapefile, read each feature, and write out the points + data in a CSV format.
The sample C++ code on the Wiki actually shows nearly every OGR API call required for this.