<commit_before>package org.ossim.omar.ogc.wfs

import geoscript.filter.Filter
import geoscript.layer.Layer
import geoscript.layer.io.GeoJSONWriter
import grails.converters.JSON
import org.joda.time.DateTime
import org.joda.time.DateTimeZone

/**
 * Created with IntelliJ IDEA.
 * User: sbortman
 * Date: 2/25/13
 * Time: 9:21 AM
 * To change this template use File | Settings | File Templates.
 */
class GeoJsonResultFormat implements ResultFormat
{
  def name = "GEOJSON"
  def contentType = 'application/json'

  def getFeature(def wfsRequest, def workspace)
  {
    def results
    def layer = workspace[wfsRequest?.typeName]
    def filter = [
        filter: wfsRequest?.filter ?: Filter.PASS,
        //sort: ""// [["<COLUMN NAME>","ASC|DESC"]]
    ]
    def filterParams = [
        filter: wfsRequest?.filter ?: Filter.PASS,
        max: wfsRequest.maxFeatures ?: -1,
        start: wfsRequest?.offset ?: -1,
        //sort: [["<COLUMN NAME>","ASC|DESC"]]
    ]
    if ( wfsRequest.sortBy )
    {

      // filterParams.sort =null//[["TITLE".toUpperCase(),"DESC"]]
      filterParams.sort = wfsRequest.convertSortByToArray();//wfsRequest.sortBy.substring()//JSON.parse( wfsRequest.sort );

      //println filterParams
    }
    try
    {
      filter = new Filter( filterParams.filter )
    }
    catch ( e )
    {
      e.printStackTrace()
    }

    if ( wfsRequest.resultType?.toLowerCase() == "hits" )
    {
      def count = layer.count( filter );
      def timestamp = new DateTime( DateTimeZone.UTC );
      results = "${[numberOfFeatures: count, timestamp: timestamp] as JSON}"
    }
    else
    {
      def writer = new GeoJSONWriter()
      def cursor = layer.getCursor( filterParams );
      def newLayer = new Layer( cursor.col )

      results = writer.write( newLayer )
      cursor?.close()
    }
    workspace?.close()
    return [results, contentType]
  }

}<commit_msg>Need to strip off workspace name when getting a reference to the layer.<commit_after>package org.ossim.omar.ogc.wfs

import geoscript.filter.Filter
import geoscript.layer.Layer
import geoscript.layer.io.GeoJSONWriter
import grails.converters.JSON
import org.joda.time.DateTime
import org.joda.time.DateTimeZone

/**
 * Created with IntelliJ IDEA.
 * User: sbortman
 * Date: 2/25/13
 * Time: 9:21 AM
 * To change this template use File | Settings | File Templates.
 */
class GeoJsonResultFormat implements ResultFormat
{
  def name = "GEOJSON"
  def contentType = 'application/json'

  def getFeature(def wfsRequest, def workspace)
  {

//    println wfsRequest

    def results
    def layerName = wfsRequest?.typeName?.split(':')[-1]
    def layer = workspace[layerName]
    def filter = [
        filter: wfsRequest?.filter ?: Filter.PASS,
        //sort: ""// [["<COLUMN NAME>","ASC|DESC"]]
    ]
    def filterParams = [
        filter: wfsRequest?.filter ?: Filter.PASS,
        max: wfsRequest.maxFeatures ?: -1,
        start: wfsRequest?.offset ?: -1,
        //sort: [["<COLUMN NAME>","ASC|DESC"]]
    ]
    if ( wfsRequest.sortBy )
    {

      // filterParams.sort =null//[["TITLE".toUpperCase(),"DESC"]]
      filterParams.sort = wfsRequest.convertSortByToArray();//wfsRequest.sortBy.substring()//JSON.parse( wfsRequest.sort );

      //println filterParams
    }
    try
    {
      filter = new Filter( filterParams.filter )
    }
    catch ( e )
    {
      e.printStackTrace()
    }

    if ( wfsRequest.resultType?.toLowerCase() == "hits" )
    {
      def count = layer.count( filter );
      def timestamp = new DateTime( DateTimeZone.UTC );
      results = "${[numberOfFeatures: count, timestamp: timestamp] as JSON}"
    }
    else
    {
      def writer = new GeoJSONWriter()
      def cursor = layer.getCursor( filterParams );
      def newLayer = new Layer( cursor.col )

      results = writer.write( newLayer )
      cursor?.close()
    }
    workspace?.close()

    return [results, contentType]
  }

}
{'fraction_non_alphanumeric': 0.12990320937340805, 'fraction_numerical': 0.005348955680081508, 'mean_word_length': 2.7435653002859866, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5220066', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1239, 'n_words': 285}