@@ -0,0 +1,2654 @@
+# (C) Copyright 2014 Voyager Search%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#  http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0Aimport base_job%0Aimport ogr%0Aimport gdalconst%0A%0Adef global_job(args):%0A    %22%22%22Create a global job object for multiprocessing.%22%22%22%0A    global job%0A    job = args%0A%0A%0Adef worker():%0A    %22%22%22Worker function to index each geometry in each feature in the datasource.%22%22%22%0A    job.connect_to_zmq()%0A    ds = ogr.Open(job.url, gdalconst.GA_ReadOnly)%0A    # Layers%0A    for l in ds:%0A        # Fields%0A        fnames = %5B%5D%0A        ldef = l.GetLayerDefn()%0A        %0A        # Layer name%0A        ln = ldef.GetName()%0A        %0A        # process or skip this layer%0A        cont = '*' in job.tables_to_keep or ln in job.tables_to_keep%0A        %0A        if cont:%0A            %0A            for i in range(ldef.GetFieldCount()):%0A                fn = ldef.GetFieldDefn(i).GetName()%0A                if '*' in job.fields_to_keep or fn in job.fields_to_keep:%0A                    fnames.append(fn)%0A                %0A            # Features%0A            for f in l:%0A                # Geometry%0A                g = f.GetGeometryRef()%0A                # Geomtry type%0A                t = g.GetGeometryType()%0A                geo = %7B%7D%0A                if t == 1: # point%0A                    geo%5B'lon'%5D = g.GetX()%0A                    geo%5B'lat'%5D = g.GetY()%0A                else:%0A                    e = g.GetEnvelope()%0A                    geo%5B'xmin'%5D = e%5B0%5D%0A                    geo%5B'xmax'%5D = e%5B1%5D%0A                    geo%5B'ymin'%5D = e%5B2%5D%0A                    geo%5B'ymax'%5D = e%5B3%5D%0A                %0A                fields = %5B%5D%0A                for i in fnames:%0A                    fields.append(f.GetField(i))%0A    %0A                entry = %7B%7D%0A                entry%5B'id'%5D = '%7B0%7D_%7B1%7D_%7B2%7D'.format(job.location_id, l.GetName(), f.GetFID())%0A                entry%5B'location'%5D = job.location_id%0A                entry%5B'action'%5D = job.action_type%0A                entry%5B'entry'%5D = %7B'geo': geo, 'fields': dict(zip(fnames, fields))%7D%0A%0A                job.send_entry(entry)%0A     %0A            %0Adef assign_job(job_info):%0A    %22%22%22Connects to ZMQ, opens the datasource, and assigns the job.%22%22%22%0A    job = base_job.Job(job_info)%0A    global_job(job)%0A    worker()

Add GDAL worker