1

I have a shapefile of size 224 MB. I am using ArcGIS to convert it to a KML file. The process involves converting the shapefile to a feature layer and then converting the layer to KML.

An alternative method that I have tried is using ogr2ogr.

In both the cases, the KML file produced is around 500 MBs. I need it to be less than 250 MBs, so I can import it as a Google Fusion table.

I was informed that one of the best ways to cut size is to reduce precision of the coordinates to 5 decimal places (from its current 10 or so).

How do I go about changing the decimal places using either ogr2ogr or ArcGIS? Is there some other software that may help in this and also, are there any other strategies I may use to reduce the size of the KML file?

I tried using Notepad++ to open the KML file and then use regular expressions to change coordinate precision but for some reason this method is not working. If I make the change and try and save the file, all the data gets deleted and the KML file size changes to 0 bytes.

An alternative strategy that I was thinking of was to split my shapefiles into two or three files and convert them to KML separately, upload them to Google fusion tables and then append those. However, I am not sure of two things.

  1. How to split shapefiles into two or three smaller shapefiles?
  2. Whether I can easily append fusion tables together to create a larger fusion table?
1

The first step in reducing the file size of a featureclass is to simplify it. This documentation explains the simplify process in ArcGIS. Basically, the more vertices your features have, the more information they are storing, and therefore the larger the file size of the feature. When you convert a shapefile to KML you are converting all of these vertices. Reduce the number of vertices and you reduce the file size.

This assumes you're using line or polygon features. If you have a ~250MB point shapefile that's a more complicated issue.

As for coordinate precision - see this great answer from @whuber.

  • Thanks for pointing to that document. How would I actually go about reducing the precision of decimals during the conversion? The Layer to KML tool does not seem to have an option for this. – user52932 Apr 23 '15 at 22:29
  • Run the Simplify Polygon or Simplify Line tool (depending on the type of shapefile). Don't worry about the coordinate precision for now - modifying this won't have as much of an effect. – Radar Apr 23 '15 at 22:31
  • Okay I will try this. I am a little concerned though because i want to use the shapefile with some satellite raster data, which is very detailed, to do computations. And, it seems as though this method might introduce inaccuracies in the computations. – user52932 Apr 23 '15 at 22:39
  • It really will depend on the accuracy of the input data (before and after simplification) and the accuracy of your satellite data. Removing point precision will also make your data less accurate (assuming it was truly accurate to start). – Radar Apr 23 '15 at 22:46
0

Two other things you can try.

First, does your shapefile have any attributes that you can drop before converting to kml?

Second, you can try to open the kml in Google Earth and save it as a kmz. This should drastically reduce the size of the file, but I'm not sure if it will solve your original problem since the kmz will still have the same amount data just compressed.

If you want to subset your shapefile before converting it you can follow these steps:

  1. Add the shapefile to ArcGIS.
  2. Select a subset of records from the shapefile.
  3. Right click on the Layer in the Table of Contents.
  4. Select Data from the pop up menu then select Export Data
  5. On the dialog make sure that Selected Features is chosen as the Export option.
  6. Specify the location and name of your output shapefile and click the OK button.
  • I kind of like this approach of creating subsets. One question though, if I create subsets and later or try and append these all together, will I get the exact same features as the original shapefile? Or is it the case that b/w the boundaries of the subsets stuff becomes inaccurate and so splitting and rejoining the data reduces accuracy? – user52932 Apr 24 '15 at 12:37
  • As long as you don't do anything to the features in the subsets you should not have a problem if you want to merge them together again. Subsetting the data in this fashion does not change the data in any way, it's just copying the selected features into new files. – dblanchett Apr 24 '15 at 13:49
0

I have just now developed a fairly full featured program that simplifies kml files. As well as gpx and tcx ones. It supports a number of techniques that make the file smaller, many are essentially loss-less, others reduce the precision of the path.

Some of the information contained in this post requires additional references. Please edit to add citations to reliable sources that support the assertions made here. Unsourced material may be disputed or deleted.

  • At the least this is not an answer and is bordering on spam – user68630 Jul 7 '16 at 5:21
  • Without a link to the library, and an example of usage, this is no way answers the question. – John Powell Jul 7 '16 at 7:59
0

Having come across the same problem, I have develop a rudimentary workaround, which is pretty quick and dirty. It almost halves the KML size but with a cost, it removes of all HTML popups and symbology/style specifications. It is good for pure viewing purposes.

I usually prefer using Generalize tool (requires at least Editor licence) to test various options until I am satisfied with the shapes that I want to process. Usually a value in between 0.5 and 0.8 meters gives me a decent outcome. A warning, the Generalize tool modifies the input data, so the best practice is to take a copy of it beforehand.

After reading the suggestions and doing some research, I have decided to develop a pretty rough python script for KML stripping process by using regular expression (intentionally avoiding XML parsing process). The code is as follows:

import re,os

kml_loc=r"C:\Temp\doc.kml"
f=open(kml_loc)
lines=f.readlines()
f.close()

all_text_0=''.join(lines)
all_text_0=' '.join(all_text_0.split())
# Remove HTML popup and shape styles
all_text_1=re.sub('<description>.*?</description>','<description></description>',all_text_0)
all_text_1=re.sub('<styleUrl>.*?</styleUrl>','',all_text_1)
all_text_2=all_text_1

# Round the coordinates to desired resolution
decimal_places_of_xy_resolution=6
for i in re.findall('<coordinates>(.*?)</coordinates>',all_text_1):
    fixed_part=' '.join([','.join(['{0:.{1}f}'.format(float(c), 
               [decimal_places_of_xy_resolution,0][c=='0']) for c in b.split(',') if c])  
               for b in i.split(' ') if b])
    all_text_2=re.sub(i,fixed_part,all_text_2,1)

# Write bew KML with a new name
new_kml=list(os.path.splitext(kml_loc))
new_kml[0]+='_REDUCTED'
f=open(''.join(new_kml),'wb')
f.write(all_text_2)
f.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.